0
0
Javaprogramming~10 mins

Java platform and JVM overview - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print "Hello, JVM!" in Java.

Java
public class Main {
    public static void main(String[] args) {
        System.[1]("Hello, JVM!");
    }
}
Drag options to blanks, or click blank then click option'
Aprintln
Becho
Cwrite
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' which does not add a new line.
Using 'write' or 'echo' which are not valid methods here.
2fill in blank
medium

Complete the code to declare a variable of type int with value 10.

Java
public class Main {
    public static void main(String[] args) {
        [1] number = 10;
    }
}
Drag options to blanks, or click blank then click option'
Adouble
Bint
CString
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'String' which is for text.
Using 'double' which is for decimal numbers.
3fill in blank
hard

Fix the error in the code to correctly create a new String object.

Java
public class Main {
    public static void main(String[] args) {
        String text = new [1]("Java");
    }
}
Drag options to blanks, or click blank then click option'
Astring
BStringBuilder
CString
DText
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'string' which is not a class in Java.
Using 'StringBuilder' which is a different class.
4fill in blank
hard

Fill both blanks to create a simple for loop that prints numbers 1 to 5.

Java
public class Main {
    public static void main(String[] args) {
        for (int i = [1]; i [2] 5; i++) {
            System.out.println(i);
        }
    }
}
Drag options to blanks, or click blank then click option'
A1
B0
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from 0 which prints 0 to 4.
Using '<' which excludes 5.
5fill in blank
hard

Fill all three blanks to create a method that returns the square of a number.

Java
public class Main {
    public static int [1](int [2]) {
        return [2] [3] [2];
    }
}
Drag options to blanks, or click blank then click option'
Asquare
Bnum
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' which adds instead of multiplies.
Using unclear variable names.