Search code examples
javastringinputinputstream

Program is not taking input from user


This is java Program I am trying the user should enter the name but program is just printing the line Enter Name of Student and no cin

System.out.println("\n\t\tAdd at least 5 members to Start the Game");   
System.out.println("\n\t\tEnter Name Of Student = ");
String name=input.nextLine();

Solution

  • You would need to use scanner like

    System.out.println("\n\t\tAdd at least 5 members to Start the Game");   
    System.out.println("\n\t\tEnter Name Of Student = ");
    
    Scanner scanner = new Scanner(System.in);
    String studentName = scanner.nextLine();
    

    Refer to this link for more details and other options