For loops
While Loops
Conditions
Operators
Math.random
100

Write a Java program using a for loop to print the numbers from 1 to 5.

 for (int i = 1; i <= 5; i++)

100

Write a Java program using a while loop to print the numbers from 1 to 5.

int i = 1; while (i <= 5) { System.out.println(i); i++; }

100

Write a Java program that checks if a number is positive and prints "Positive" if it is. You can initialize a variable to any value.

int number = 5; if (number > 0) { System.out.println("Positive"); }

100

This operator in Java returns the remainder of a division operation.

What is modulo or %.

100

To generate a random integer between 1 and 8 using Math.random(), you multiply the result of Math.random() by this number, then add 1.

What is 8

200

Write a Java program using a for loop to print the numbers from 1 to 10

for (int i = 1; i <= 10; i++) { System.out.println(i); }

200

Write a Java program using a while loop to print the numbers from 1 to 10.

int i = 1; while (i <= 10) { System.out.println(i); i++; }

200

Write a Java program that checks if a number is positive or negative and prints "Positive" or "Negative".

if (number > 0) { System.out.println("Positive"); } else { System.out.println("Negative"); }

200

Given two integers a and b, write a Java statement to find the remainder when a is divided by b.

What is int remainder = a % b;

200

To generate a random integer between 0 and 35 using Math.random(), you multiply the result of Math.random() by this number, then add this number.

What is 36 and 0

300

Write a Java program using a for loop to print the first 10 even numbers.

for (int i = 1; i <= 10; i++) { System.out.println(2 * i); }

300

Write a Java program using a while loop to print the first 10 even numbers.

int i = 1; while (i <= 10) { System.out.println(2 * i); i++; }

300

Write a Java program that checks if a number is even or odd and prints "Even" or "Odd".

if (number % 2 == 0) { System.out.println("Even"); } else { System.out.println("Odd"); }

300

Write a Java statement to determine if a number n is even.

What is n%2 ==0

300

If you want a random integer between 10 and 100 using Math.random(), what do you multiply Math.random() by and what do you add to it?

What is multiply by 91 and add 10

400

Write a Java program using a for loop to print the first 10 multiples of 5.

for (int i = 1; i <= 10; i++) { System.out.println(5 * i); }

400

Write a Java program using a while loop to print the numbers from 10 down to 1.

int i = 10; while (i > 0) { System.out.println(i); i--; }

400

Write a Java program that checks if a number is positive, negative, or zero and prints "Positive", "Negative", or "Zero".

if (number > 0) { System.out.println("Positive"); } else if (number < 0) { System.out.println("Negative"); } else { System.out.println("Zero"); }

400

To check if an integer x is divisible by 5, you would check if this expression is true.

What is x % 5 == 0

400

What is the range of random integers generated by (Math.random() * 22) + 5?

What is 5 to 26?

500

Write a Java program using a for loop to print the squares of the numbers from 1 to 10.


for (int i = 1; i <= 10; i++) { System.out.println("Square of " + i + " = " + (i * i)); }

500

Write a Java program using a while loop to print the squares of the numbers from 1 to 10.

int i = 1; while (i <= 10) { System.out.println("Square of " + i + " = " + (i * i)); i++; }

500

Write a Java program that checks if a year is a leap year. A year is a leap year if it is divisible by 4 but not divisible by 100, except if it is also divisible by 400.

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { System.out.println("Leap Year"); } else { System.out.println("Not a Leap Year"); }



500

In a loop, this condition can be used with the modulo operator to execute code every 3rd iteration and 5th iteration.

What is if (i % 3 == 0 && i %5 == 0)

500

To generate a random integer between -10 and 20 using Math.random(), you multiply Math.random() by this number, then add this number.

What is 31 and -10?