This Java file contains the classic Hello World program in Java. Try tinkering with the code in the following ways to see what happens.
- Change the class from
HelloWorldtohelloworld. Recompile. What happens? Change it back. - In the line containing
System.out.println("Hello, world!");, try leaving out a quotation mark or the semi-colon. Recompile. What happens? Change it back. - Try manipulating the "Hello, World!" String to say something else. Recompile.
- Based on your knowledge of programming, add the following line before the
System.out.println().String name = "Sam";Try to get the line to print out what the value ofnameis. Notice that in Java, we need to declare the types of variables.
- Add the line
import java.util.Scanner;above the HelloWorld class declaration. - Add the following lines lines below
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String name = sc.next();
sc.close();Remove the line String name = "Sam";