+ 2
This java program is not running. Please tell me where it is wrong ? (User Input)
4 Answers
+ 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");
}
}
+ 1
Yeah
+ 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();)
0
You dont need to create second Scanner object to take user input. Use myVar Scanner.



