Question 1
A Java program uses Scanner to read a user's age. Which statement correctly creates a Scanner object that reads from standard input?
Show answer & explanation
Correct answer: A - Scanner input = new Scanner(System.in);
10 exam-style questions with answers and explanations, straight from our 1,030-question bank. Tap an answer to check yourself. When you're ready, take the scored version in the free practice test.
The CHS-J1 exam has 45 questions and runs 1 hours 30 minutes.
These 10 free CHS-J1 questions are organized by exam domain, so you can see how each part of the CodeHS Java Level 1 (CHS-J1) blueprint is tested. Reveal the answer and explanation under each question.
A Java program uses Scanner to read a user's age. Which statement correctly creates a Scanner object that reads from standard input?
Correct answer: A - Scanner input = new Scanner(System.in);
A method declares an int variable named total inside its body. Another method in the same class attempts to use total directly. What is the most accurate explanation?
Correct answer: B - The variable is only accessible within the method where it is declared
What value is stored in result after this code executes? int a = 7; double result = a / 2;
Correct answer: B - 3.0
A programmer wants to convert the String value "42" into an integer before performing arithmetic. Which approach is appropriate?
Correct answer: A - Integer.parseInt("42")
A program contains an ArrayList of student names. The programmer needs to examine every name without changing the list. Which approach best matches this task?
Correct answer: B - Use traversal that visits each element in sequence
A two-dimensional int array is declared as int[][] scores = new int[3][4]; What does this declaration create?
Correct answer: A - Three rows and four columns of integer storage
A programmer writes if (x > 5 && x < 10). For which value of x will the condition evaluate to true?
Correct answer: C - 7
What is printed by this loop? for (int i = 1; i <= 3; i++) { System.out.print(i); }
Correct answer: A - 123
A developer needs a loop that continues running as long as a user's input remains valid, but the number of repetitions is unknown before execution. Which loop is most appropriate?
Correct answer: A - A while loop controlled by the validity condition
A class named Book has an instance variable title and a static variable totalBooks. Which statement is correct?
Correct answer: C - title can differ between objects while totalBooks is shared by the class
The CHS-J1 exam also covers these domains. Drill them in the full free practice test:
The full bank has 1,020 more CHS-J1 questions with explanations.
Continue in the free practice test →
View plans