True or False: This is what the main method looks like:
public void main(String args) {
}
False
How would you raise 2 to the y power?
Math.pow(2, y)
True or False: While loops and Do-While loops operate based on a condition.
True
List 3 types of primitive variables.
Any 3 of the following: int, double, char, boolean, float, long, short, byte
What are the two values that conditional statements can evaluate to?
True or false.
True or false: You do not put semicolons at the end of a loop or conditional statement
True
double myDouble = 20.0 % 4.0;
What is the numerical value of myDouble?
myDouble = 5.0
What type of loop does this flow chart illustrate?
Do while loop
What is the difference between = and ==?
= assigns variables, while == checks a boolean condition.
Write a simple if statement that prints only out a number n if it is even.
if (n%2 == 0)
System.out.println (""+n);
Which Scanner method returns an integer?
nextInt(), nextDouble()
int myInt = 3 / 4;
What is the numerical value of myInt?
myInt = 0
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++)
True or false: Strings are a type of primitive variable.
False
True or false: Statements with an else-if do not have to also have an if at the beginning.
False
What does Math.random()*2+30 return?
It returns a random double between 30 and 32.
What are the three parts of a for-loop? (Describe them if you don't know the exact name)
Initialization, condition, and change
int myInt = 8;
How would you cast myInt into a double?
double myDouble = (double) myInt;
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
}
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.
How do you come up with a random integer value between 1 and 45?
int myInt = (int) (Math.random()
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();
}
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.
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.");
}