0

help me with the code

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner myvar= new Scanner(System.in); System.out.println(myvar.nextLine()); switch(myvar) { case 1:System.out.println("one"); break; case 2:System.out.println("two"); break; } } }

17th Aug 2016, 6:24 AM
rajat kumar raicha
rajat kumar raicha - avatar
2 ответов
+ 4
Let me rework your code so you have a better understanding of what you're doing. Scanner reader = new Scanner(System.in); int myVar = reader.nextInt(); When you create a scanner, youre just assigning a variable to utilize the Scanner class, not to save input, just retrieve it. Now, you create a variable that takes what the scanner gets, and saves it to a variable. I set it up so it only accepts an int input since your switch calls for it.
17th Aug 2016, 6:45 AM
James
James - avatar
0
thanks james. it worked.
17th Aug 2016, 7:22 AM
rajat kumar raicha
rajat kumar raicha - avatar