0
What's wrong with this?
5 Answers
0
1. On Java you can't use a variable without creating it first.
enter = sc.nextString(); //wrong, enter doesn't exist yet.
String enter;
Do:
String enter = sc.nextLine();
0
After if you're using x, and x is always 5 (you didn't change neither receive it from user.
So:
if(x>5 || x < 10) will never run, because x=5 (> should be bigger than, equal is false).
Then if(x > 5 == x < 10)
x > 5 is false
x < 10 false
And you're comparing: false==false? Yes. So it will run.
Output: Enter higher number
0
int xx = Integer.valueOf(String);
You're passing a Object there, the String dataType, you should pass a string, not the String.
Example:
int xx = Integer.valueOf("3"); //" " indicate it is a string.
0
else if(contition)
{}
You didn't put the conditional, or you should use just "else"
if(condition)
{}
else if(condition_1)
{}
else if(condition_n) //can have any else if, 0 or any amount
{}
else //can have 0 or 1 else, it doesn't have condition
{}
0
And the code is complicate, not sure what it should do.
The output for both if is the same, so if you're testing you would not know which if come in.
And you could so put all on same if then.
Example:
if(x > 5)
{
System.out.println("my message");
}
else if(x < 5)
{
System.out.println("my message");
}
Both will do same input wherever go in, so:
if(x > 5 || x < 5)
{
System.out.println("my message");
}