Last Updated: January 3, 2026
31 quizzes
Complete the statement so the program reads an integer from standard input using an existing Scanner named scanner
int age = scanner.();Click an option to fill the blank:
Complete the statement so the variable userName refers to a new String object from an existing text variable
String userName = new (text);Click an option to fill the blank:
Complete the statement so result holds the remainder when total is divided by 2
int result = total 2;Click an option to fill the blank:
Which declaration defines a local variable that can store a person's age in whole years?
Which primitive type is best suited to represent a true/false flag?
Which statement about reference types in Java is correct?
What is the result type of the expression 5 / 2 in Java when both operands are int?
Which casting operation requires explicit casting syntax?
Which line correctly creates a Scanner to read from standard input?
How is a single-line comment written in Java?
Which variable name follows standard Java naming conventions for a boolean flag?
Which declaration defines a constant in Java that represents the maximum number of users?
Which primitive type is best for representing the mathematical constant pi with decimals?
Which statement about local variables is true?
Order the steps to read a user's name from the console and print a greeting using Scanner
Drag and drop to reorder, or use the arrows.
Order the steps to declare, initialize, and use an instance variable in a class
Drag and drop to reorder, or use the arrows.
What is the output of this code?
1int a = 7;
2int b = 3;
3int result = a / b * b;
4System.out.println(result);What is the output of this code?
1byte x = 100;
2byte y = 27;
3int sum = x + y;
4System.out.println(sum);What is the output of this code?
1char letter = 'A';
2int code = letter + 1;
3System.out.println(code);What is the output of this code?
1double price = 19.99;
2int rounded = (int) price;
3System.out.println(rounded);What is the output of this code?
1String firstName = "Ada";
2String lastName = "Lovelace";
3System.out.println(firstName + " " + lastName.length());Find the bug in this code that reads an age and prints it
Click on the line(s) that contain the bug.
import java.util.Scanner; public class AgeReader { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int age; System.out.print("Enter age: "); age = scanner.nextLine(); System.out.println("Age: " + age); scanner.close(); }}Find the bug in this code that calculates a discount using doubles
Click on the line(s) that contain the bug.
public class DiscountCalculator { public static void main(String[] args) { double price = 50.0; double discountRate = 0.1; double finalPrice = price - price * (int) discountRate; System.out.println(finalPrice); }}Match each operator with its category
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each naming convention with the corresponding Java element
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to declare a constant for maximum attempts and read the first attempt count from the user
import java.util.Scanner;public class LoginAttempts { public static void main(String[] args) { int MAX_ATTEMPTS = 3; Scanner scanner = new Scanner(System.in); System.out.print("Enter attempts used: "); int used = scanner.(); System.out.println("Remaining: " + (MAX_ATTEMPTS - used)); scanner.close(); }}Click an option to fill blank 1:
Complete the code to store a user's initial and age using appropriate primitive types
public class UserInfo { public static void main(String[] args) { initial = 'J'; age = 25; System.out.println(initial + " is " + age + " years old"); }}Click an option to fill blank 1:
Complete the code to safely narrow a long value to an int and print it
public class CastExample { public static void main(String[] args) { long big = 1000L; int smaller = big; System.out.println(); }}Click an option to fill blank 1:
Complete the code to use a boolean variable that follows naming conventions and a comment explaining its purpose
public class FeatureToggle { public static void main(String[] args) { // indicates if the beta feature is enabled boolean = true; if () { System.out.println("Beta feature is ON"); } }}Click an option to fill blank 1:
Click the line that defines a static variable shared by all instances
Click on the line to select.
public class Counter { int instanceCount = 0; static int totalCount = 0; public void increment() { instanceCount++; totalCount++; }}Click the line that will cause a NullPointerException at runtime
Click on the line to select.
public class ReferenceTest { public static void main(String[] args) { String message = null; System.out.println(message.length()); }}