import java.util.*;
public class SimpleProgram
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter three integers on one line.");
int num = input.nextInt();
num += input.nextInt();
num += input.nextInt();
System.out.println("Enter your name on a new line.");
String name = input.nextLine(); // Program produces logic error if this line does not use the nextLine method (ie. String name;) in conjunction with the next line.
name = input.nextLine(); // Necessary to avoid an odd logic error, previous nextLine method does not 'appear' to occur during runtime.
System.out.println(name + " owes Steven $" + num + ".");
}
}
Why is: name = input.nextLine(); necessary?
I wrote the program but I commented to just make the problem clear in the code.