Java Basics Quiz
Test your Java skills! This quiz checks if you’re ready for FRC programming.
Each question shows the answer immediately so you can learn as you go.
Question 1: Variables
Section titled “Question 1: Variables”What does this code print?
int score = 10;score = score + 5;System.out.println(score);Show Answer
Answer: 15
Why?
- First line:
scoreis set to 10. - Second line:
score + 5= 15, thenscore = 15 - Third line: Prints 15.
Think of it like:
- You have a box labeled “score”.
- Put 10 in the box.
- Add 5 more to the box.
- Now the box has 15.
Question 2: Strings
Section titled “Question 2: Strings”What does this code print?
String name = "FRC";String greeting = "Hello " + name;System.out.println(greeting);Show Answer
Answer: Hello FRC
Why?
+joins strings together (called concatenation)"Hello " + "FRC"="Hello FRC"
Think of it like:
- Glue two pieces of paper together.
- One says “Hello ”, the other says “FRC”.
- After gluing: “Hello FRC”.
Question 3: If Statements
Section titled “Question 3: If Statements”What does this code print?
int speed = 7;if (speed > 5) { System.out.println("Fast!");} else { System.out.println("Slow");}Show Answer
Answer: Fast!
Why?
speedis 77 > 5is true.- Run the code inside
if - Skip the code inside
else
Think of it like:
- “Is the speed greater than 5?”.
- Yes! Print “Fast!”.
- No need to check the “else” part.
Question 4: If-Else If
Section titled “Question 4: If-Else If”What does this code print?
int score = 85;if (score >= 90) { System.out.println("A");} else if (score >= 80) { System.out.println("B");} else { System.out.println("C");}Show Answer
Answer: B
Why?
scoreis 8585 >= 90? No, skip first block.85 >= 80? Yes! Print “B”.- Skip the
elseblock.
Think of it like:
- Check conditions in order.
- Stop at the first one that’s true.
- Don’t check the rest.
Question 5: Loops
Section titled “Question 5: Loops”How many times does this print?
for (int i = 0; i < 3; i++) { System.out.println("Hello");}Show Answer
Answer: 3 times
Why?
i = 0: Print (i is 0, 0 < 3)i = 1: Print (i is 1, 1 < 3)i = 2: Print (i is 2, 2 < 3)i = 3: Stop (i is 3, 3 < 3 is false)
Think of it like:
- Count: 0, 1, 2.
- That’s 3 numbers.
- Print 3 times
Question 6: While Loops
Section titled “Question 6: While Loops”What does this code print?
int count = 3;while (count > 0) { System.out.println(count); count = count - 1;}Show Answer
Answer:
321Why?
count = 3: 3 > 0? Yes, print 3, then count becomes 2.count = 2: 2 > 0? Yes, print 2, then count becomes 1.count = 1: 1 > 0? Yes, print 1, then count becomes 0.count = 0: 0 > 0? No, stop.
Think of it like:
- Keep going while the condition is true.
- Stop when it becomes false.
Question 7: Methods
Section titled “Question 7: Methods”What does this code print?
public int add(int a, int b) { return a + b;}
// Somewhere else:int result = add(3, 4);System.out.println(result);Show Answer
Answer: 7
Why?
- Call
add(3, 4) a = 3,b = 4return 3 + 4= 7.result = 7- Print 7
Think of it like:
- A method is a recipe.
- Give it ingredients (3 and 4)
- It cooks them together (adds them)
- Gives you the result (7)
Question 8: Boolean Logic
Section titled “Question 8: Boolean Logic”What does this code print?
boolean hasPermission = true;boolean isAdmin = false;if (hasPermission && isAdmin) { System.out.println("Access granted");} else { System.out.println("Access denied");}Show Answer
Answer: Access denied
Why?
hasPermissionis true.isAdminis false.true && false= false.- Run the
elseblock.
Think of it like:
&&means “both must be true”.- One is false, so the whole thing is false.
- Like saying “I have a ticket AND I’m VIP”.
- If you don’t have VIP, you can’t get in.
Question 9: Arrays
Section titled “Question 9: Arrays”What does this code print?
int[] scores = {10, 20, 30};System.out.println(scores[1]);Show Answer
Answer: 20
Why?
- Arrays start at index 0.
scores[0]= 10.scores[1]= 20.scores[2]= 30.
Think of it like:
- Mailboxes on a street.
- Address 0 has mail (10)
- Address 1 has mail (20)
- Address 2 has mail (30)
- You check address 1: you get 20.
Question 10: Objects
Section titled “Question 10: Objects”What does this code print?
public class Robot { public String name;
public Robot(String robotName) { name = robotName; }}
Robot myRobot = new Robot("MARS");System.out.println(myRobot.name);Show Answer
Answer: MARS
Why?
- Create a new Robot with name “MARS”.
- Constructor sets
name = "MARS" - Access
myRobot.name - Print “MARS”
Think of it like:
- A class is a blueprint for a house.
- An object is the actual house built from the blueprint.
- You can build many houses from one blueprint.
- Each house can have different features.
Question 11: Null
Section titled “Question 11: Null”What happens with this code?
String name = null;System.out.println(name.length());Show Answer
Answer: NullPointerException (crashes!)
Why?
nameisnull(nothing)- Can’t call methods on nothing.
- Java throws an error.
How to fix:
String name = null;if (name != null) { System.out.println(name.length());}Think of it like:
- Trying to open a door that doesn’t exist.
- You can’t do it!
- Check if the door exists first.
Question 12: Increment
Section titled “Question 12: Increment”What does this code print?
int count = 5;count++;System.out.println(count);Show Answer
Answer: 6
Why?
count++means “add 1 to count”.- Same as
count = count + 1 - 5 + 1 = 6
Think of it like:
- A shortcut for adding 1.
- programmers are lazy!
++is shorter than+ 1
Question 13: Modulo
Section titled “Question 13: Modulo”What does this code print?
int x = 10 % 3;System.out.println(x);Show Answer
Answer: 1
Why?
%is the modulo operator (remainder)- 10 ÷ 3 = 3 with remainder 1.
- So 10 % 3 = 1
Think of it like:
- You have 10 cookies.
- Divide into groups of 3.
- You get 3 groups (9 cookies)
- 1 cookie left over.
- That’s the remainder!
Question 14: Equality
Section titled “Question 14: Equality”What does this code print?
String a = new String("hello");String b = new String("hello");if (a == b) { System.out.println("Same");} else { System.out.println("Different");}Show Answer
Answer: Different
Why?
==checks if they’re the SAME object..equals()checks if they have the SAME VALUE.aandbare different objects with same value.
How to fix:
if (a.equals(b)) { System.out.println("Same"); // This prints!}Think of it like:
- Two different cookies.
- Both are chocolate chip.
- They’re not the SAME cookie.
- But they’re the same TYPE of cookie.
Question 15: Scope
Section titled “Question 15: Scope”What does this code print?
int x = 5;if (true) { int x = 10; // Line A System.out.println(x); // Line B}System.out.println(x); // Line CShow Answer
Answer: This code doesn’t compile!
Why?
- Can’t declare
xtwice in the same scope. - The outer
xis still visible inside the if. - Java doesn’t know which
xyou mean.
Fix:
int x = 5;if (true) { x = 10; // Just assign, don't redeclare}System.out.println(x); // Prints 10Think of it like:
- You can’t have two people with the same name in the same room.
- But you can have different people with same name in different rooms.
Scoring
Section titled “Scoring”Count your correct answers:
- 13-15 correct: 🌟 Amazing! You’re ready for advanced FRC programming!
- 10-12 correct: 👍 Great job! You understand most Java basics.
- 7-9 correct: 👌 Good start! Review the questions you missed.
- Below 7: 📚 Keep learning! Try the Beginner Learning Path.
What to Learn Next
Section titled “What to Learn Next”If you got 13-15 correct:
- → Ready for Intermediate Learning Path
- → Learn about FRC Programming
- → Build your first Robot Command
If you got 7-12 correct:
- → Review Java Basics
- → Practice more Examples
- → Try the Beginner Learning Path
If you got below 7:
- → Start with Beginner Learning Path
- → Learn Java from Scratch
- → Ask questions in our community
Practice More
Section titled “Practice More”Write your own code:
- Make a calculator that adds two numbers.
- Write a program that counts to 10.
- Create a method that finds the larger of two numbers.
- Build an array of your favorite foods.
Test yourself:
// Challenge 1: Make this print "Hello World" 5 times// Your code here
// Challenge 2: Make a method that returns true if a number is even// Your code here
// Challenge 3: Find the largest number in this array: {5, 2, 9, 1, 7}// Your code hereRemember: Programming is a skill. Keep practicing and you’ll get better!
Stuck on a question? Ask for help - we’re here to help you learn!