+ 1
I made a code to get user input, and i want to add the input value to an "if" condition. But i don't know what do i have to white inside the condition to add the value.
My problem example:import java.util.scannerpublic class -- {public static void main(String[] args) { Scanner MyVar = newScanner(System.in)System.out.print(MyVar.nextInt());if (i don't know what to write == x) {System.out.print...
4 ответов
+ 3
Well unless you specifically want to write the value of MyVar to the console, I would store it in a matching variable. Preferably a String for parsing later on (you can check what format MyVar is by using InstanceOf(kindOfVariable)). Then use the parsed variable in your condition
+ 2
the right x must be a number
+ 1
int value = MyVar.nextInt();
System.out.print(value);
if(value==x){
–---------
}
This will work, provided x is an integer.
0
if (MyVar==x)