Complete the code to print "Hello, JVM!" in Java.
public class Main { public static void main(String[] args) { System.[1]("Hello, JVM!"); } }
The println method prints the text and moves to a new line, which is the standard way to output in Java.
Complete the code to declare a variable of type int with value 10.
public class Main { public static void main(String[] args) { [1] number = 10; } }
The int type is used to store whole numbers like 10.
Fix the error in the code to correctly create a new String object.
public class Main { public static void main(String[] args) { String text = new [1]("Java"); } }
The class name String must be capitalized exactly to create a new String object.
Fill both blanks to create a simple for loop that prints numbers 1 to 5.
public class Main { public static void main(String[] args) { for (int i = [1]; i [2] 5; i++) { System.out.println(i); } } }
The loop starts at 1 and continues while i is less than or equal to 5 to print numbers 1 through 5.
Fill all three blanks to create a method that returns the square of a number.
public class Main { public static int [1](int [2]) { return [2] [3] [2]; } }
The method named 'square' takes an integer 'num' and returns its multiplication by itself.