Skip to content

Monarch-High-School/JavaHelloWorld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Java Hello World

This Java file contains the classic Hello World program in Java. Try tinkering with the code in the following ways to see what happens.

  1. Change the class from HelloWorld to helloworld. Recompile. What happens? Change it back.
  2. 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.
  3. Try manipulating the "Hello, World!" String to say something else. Recompile.
  4. 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 of name is. Notice that in Java, we need to declare the types of variables.

Get user input

  1. Add the line import java.util.Scanner; above the HelloWorld class declaration.
  2. 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";

About

This is the classic Hello World program in Java.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages