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?
Can you answer this question?
Write Answer1 Answers