import java.util.Scanner;
public class ScannerIssue {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter an integer");
int i = sc.nextInt();
System.out.println("Enter a String");
String j = sc.nextLine();
System.out.println(i);
System.out.println(j);
sc.close();
}
}
Now the output is
Enter an integer
6
Enter a String
6
i.e it skipped the input from nextLine() method and only prompting input once for integer and print its value
What is going wrong in this code?
Anonymous User
09-Oct-2015