-2

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();
javadev
  • 688
  • 2
  • 6
  • 17

1 Answers1

0

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

Ravik
  • 694
  • 7
  • 12
  • This is working perfectly Thanks for sharing. As i have defined the Scanner in main program and inside the case 1 of switch i declared another variable in which i am taking input from user. can i get know why my code is not working? – zulkefal mohammadzai Oct 31 '21 at 11:07
  • You didn’t mentioned scanner in your question. You need to share detailed code to understand the root cause. Can you share the reason for down voting? – Ravik Oct 31 '21 at 11:58