As an example. Given the following program that promts the user for their last and first names and prints a greeting of the form
Hello first name last name!!
import java.util.*;
public class Hello {
public static void main(String [] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter last name: "); // prompt
String lastName = scanner.next();
System.out.print("Enter first name: "); // prompt
String firstName = scanner.next();
System.out.println("Hello " + firstName + " " + lastName + "!!"); // output
}
}
- Here is what the execution would look like if you ran the program (notice — no bold):
Enter last name: Weiss
Enter first name: Gerald
Hello Gerald Weiss!!
- Here is what how the execution is displayed on the lab page (as well as in the CodeLab instructions for the exercise (notice the bold):
Enter last name: Weiss
Enter first name: Gerald
Hello Gerald Weiss!!
- In both of the above cases, you see the user input entered from the keyboard. But the actual output produced by the program
(i.e., the output produced from the
print
or println
messages sent to System.out
) is actually:
Enter last name: Enter first name: Hello Gerald Weiss!!
- Notice the absence of any of the user input (that was not printed by the program's
print
message)
- This is what CodeLab will display as your program's output (it will also display similar user-inputless
output for the expected output).
- This takes a bit getting used to, but since both your output and the expected output are displiayed this way
it should not be too difficult for you to find the discrepancies.