returns
parameters
edge cases
121 review
for loops
100

True or False: A method with a return type of void must include a return statement.

False!
100

True or False: You can pass multiple parameters into a method.

True

100

What range of numbers can
ran.nextInt(5) produce?

0 - 4

100

What is the difference between = and == in Java?

= assigns a value; == compares values.

100

How many times does this loop run? for (int i = 0; i < 5; i++)

5 times

200

What happens if you write a return statement before the end of the method body?

The method stops executing immediately and exits.

200

What is printed?  

public static void greet(String name) {         System.out.println("Hi " + name);
}

greet("Sthiti");

"Hi Sthiti"

200

What does this print?
 String a = "hi";
String b = "hi";
System.out.println(a == b);

true

200

What data type would you use for a decimal number?

double or float

200

What are the three parts inside a for loop header?

Initialization, condition, update

300

What will this method return?  

public static int multiply(int a, int b) {
     return a * b;
}

when called with multiply(2, 3)

6

300

What happens if you call a method without passing all required arguments in the correct order?

You get a compile-time error.

300

What is printed?  System.out.println("Java".substring(1, 3));

"av" — substring starts at 1 and ends before 3.

300

What happens if the loop condition is always true and never updated?

Infinite loop

400

What happens if a method with a non-void return type doesn’t have a return statement in all paths?

Compilation error — Java requires a return statement for every possible execution path.

400

What is the output?

 System.out.println(Math.max(5, Math.min(2, 10)));

5 — Math.min(2,10) is 2, then Math.max(5,2) is 5.

500

Can a method have more than one return statement?

Yes, but only one will execute, depending on the condition.

500

What is it called when two methods have the same name but different parameter types or counts?

Method overloading

500

What is the result of Math.pow(2, 3) == 8?

true but first looks at it as a double

M
e
n
u