0
import java.util.Scanner;

public class test{
    public static void main(String args[]){
      String branch;
      String Name;
      String course;
      int Age;
      int Roll;
      int counter = 1;
      int pin;
    
    Scanner s = new Scanner(System.in);
    
    {
        System.out.print("Enter your Name : ");
        Name = s.nextLine();
        System.out.print("Enter your Age : ");
        Age = s.nextInt();
        System.out.print("Enter your Branch : ");
        branch = s.nextLine();
        System.out.print("Enter your PIN : ");
        pin = s.nextInt();
        System.out.print("Enter your Course : ");
        course = s.nextLine();
        Roll = counter++;

    }
    }
} 

As shown in image, user input for Branch and Course is skipped

This code is for Data Entry. While running this code command Prompt did not asked for user input for Branch and Course which are of type string. Why does this happen?

khelwood
  • 52,115
  • 13
  • 74
  • 94
  • Keep in mind. If you are going to use `nextLine()` then use it for everything (instead of `next(), nextFoo()`, etc) otherwise **don't use it at all**. Use `next()` instead but make use of the [Scanner#useDelimiter()](https://www.tutorialspoint.com/java/util/scanner_usedelimiter_string.htm) method: `Scanner s = new Scanner(System.in).useDelimiter("\\R");`. Now change all the `nextLine();`'s to `next();`. Try your application again. – DevilsHnd Apr 14 '22 at 10:11

0 Answers0