+ 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...

3rd Sep 2016, 2:22 PM
Silas Junior
Silas Junior - avatar
4 Answers
+ 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
3rd Sep 2016, 4:42 PM
Jim Vekemans
Jim Vekemans - avatar
+ 2
the right x must be a number
18th Jan 2017, 5:19 AM
xuyexu
xuyexu - avatar
+ 1
int value = MyVar.nextInt(); System.out.print(value); if(value==x){ –--------- } This will work, provided x is an integer.
3rd Sep 2016, 6:09 PM
Mahender
Mahender - avatar
0
if (MyVar==x)
3rd Sep 2016, 3:39 PM
abi