I used the current code to check the difference between nextLine()
and next()
Scanner sc = new Scanner(System.in);
System.out.print("Add a String\n");
String string1 = sc.next();
System.out.println(string1);
String string2=sc.nextLine();
System.out.println(string2);
when I was executing the program, it displayed "Add a string" for the first entry and I was able to enter the first string, but I was not able to enter the second string.
I want to know why and how to fix that.