0

In here why java is not taking input From String = sc.nextLine(); It just skip that part and jump directly to if statement

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    System.out.print("Enter value between 1 or 2 : ");
    int a = sc.nextInt();

    System.out.println("Enter String value : ");
    String str = sc.nextLine(); //Java Skips this part

    if (a==1){
        System.out.println(str + "1");
    }
    else{
        System.out.println(str + "2");
    }

}
  • This is one of first problems new programmers face while starting using Scanner. See [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/q/13102045) – Pshemo May 01 '21 at 20:15

0 Answers0