+ 2

This java program is not running. Please tell me where it is wrong ? (User Input)

https://code.sololearn.com/cWQeCy4WYDYv/?ref=app

18th Jun 2018, 3:22 PM
Kumar Purushottam
Kumar Purushottam - avatar
4 ответов
+ 1
IS IT CORRECT import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner myVar = new Scanner(System.in); System.out.println(myVar.nextLine()); System.out.println("thanks"); System.out.println("what is you name"); System.out.println(myVar.nextLine()); System.out.println("ok fine"); } }
18th Jun 2018, 3:37 PM
Kumar Purushottam
Kumar Purushottam - avatar
+ 1
Yeah
18th Jun 2018, 3:39 PM
Sad
Sad - avatar
+ 1
//This code are work. import java.util.Scanner; class MyClass { public static void main(String[ ] args) { System.out.println("what is you name and how old are you?"); Scanner sc = new Scanner(System.in); String name = sc.nextLine(); int age = sc.nextInt(); //System.out.println(myVar.nextLine()); System.out.println(name); System.out.println("thanks"); //System.out.println("what is you name"); //Scanner myLife = new Scanner(System.in); System.out.println(age); System.out.println("ok fine"); sc.close(); } } //If you want create two Scanner, your need close first funcrion(use sc.close();)
18th Jun 2018, 6:48 PM
Mikhail Fedorenko
0
You dont need to create second Scanner object to take user input. Use myVar Scanner.
18th Jun 2018, 3:33 PM
Sad
Sad - avatar