Syntax
Java Math
Loops
Variables
Conditional Logic and If-else Statements
100

True or False: This is what the main method looks like:

public void main(String args) {

}

False

100

How would you raise 2 to the y power?

Math.pow(2, y)

100

True or False: While loops and Do-While loops operate based on a condition.

True

100

List 3 types of primitive variables.

Any 3 of the following: int, double, char, boolean, float, long, short, byte

100

What are the two values that conditional statements can evaluate to?

True or false.

200

True or false: You do not put semicolons at the end of a loop or conditional statement

True

200

double myDouble = 20.0 % 4.0;

What is the numerical value of myDouble?

myDouble = 5.0

200

What type of loop does this flow chart illustrate?

Do while loop

200

What is the difference between = and ==?

= assigns variables, while == checks a boolean condition.

200

Write a simple if statement that prints only out a number n if it is even.

if (n%2 == 0)

     System.out.println (""+n);

300

Which Scanner method returns an integer?

nextInt(), nextDouble()


300

int myInt = 3 / 4;

What is the numerical value of myInt?

myInt = 0

300

How do you write a for loop that iterates 10 times?

for(int i = 0; i < 10; i++) OR

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

300

True or false: Strings are a type of primitive variable.

False

300

True or false: Statements with an else-if do not have to also have an if at the beginning.

False

400

How do you create a new Scanner to read from the keyboard?

Scanner sc = new Scanner(System.in);

400

What does Math.random()*2+30 return?

It returns a random double between 30 and 32.

400

What are the three parts of a for-loop? (Describe them if you don't know the exact name)

Initialization, condition, and change

400

int myInt = 8;

How would you cast myInt into a double?

double myDouble = (double) myInt;

400

Write the syntax for an if...else if... else statement (there does not need to be code inside the statements themselves, and you can make up any conditions you want)

if (//condition) {

//block of code

}

else if (//condition) {

//block of code

}

else {

//block of code

}

500

What is the difference between the Scanner methods String next() and String nextLine()? 

next() returns a String with no spaces, while nextLine() returns a String with multiple spaces.

500

How do you come up with a random integer value between 1 and 45?

int myInt = (int) (Math.random()

500

Write a while loop to continuously prompt a user to enter a number if their number is greater than 20. (Use Scanners here!)

Scanner sc = new Scanner(System.in)

int num = sc.nextInt();

while(num > 20) {

        System.out.println("Enter a new number!");

        num = sc.nextInt();

}

500

What is the difference between declaring and assigning variables?

Assigning variables assigns a value to a variable while declaring a variable does not assign a value.

500

Write the conditional statement for checking if an integer x is divisible by three and negative.

if(x %3 == 0 && x < 0) {

System.out.println("x is divisible by three and negative.");

}

M
e
n
u