Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "Hello, World!" to the console.
Java
public class HelloWorld { public static void main(String[] args) { System.out.[1]("Hello, World!"); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of println may not add a new line after output.
✗ Incorrect
The println method prints the text and moves to a new line, which is the standard way to output text in Java.
2fill in blank
mediumComplete the code to declare the main method correctly.
Java
public class Main { public static void [1](String[] args) { System.out.println("Welcome!"); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using other method names like start or run will not run the program automatically.
✗ Incorrect
The main method must be named main for the Java program to start execution there.
3fill in blank
hardFix the error in the class declaration to make it valid Java code.
Java
public [1] HelloWorld { public static void main(String[] args) { System.out.println("Hi!"); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase Class causes a syntax error.
✗ Incorrect
The keyword to declare a class in Java is class in lowercase.
4fill in blank
hardFill both blanks to complete the program that prints a greeting.
Java
public [1] Greeting { public static void main(String[] [2]) { System.out.println("Hello!"); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase Class or argv instead of args.
✗ Incorrect
The class declaration uses class and the main method parameter is usually named args.
5fill in blank
hardFill all three blanks to complete the Java program that prints a message.
Java
public [1] MessagePrinter { public static void main(String[] [2]) { System.out.[3]("Message printed!"); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase Class, argv, or print instead of println.
✗ Incorrect
The class keyword is class, the main method parameter is args, and the print method is println.