Java math
What does the code execute?
True or false
Math library
Random!
100

177 % 100 % 10 /2

What is 3?

100

What is the value of n after the code is executed?

int n = 3;

int m = n;

n--;

m++;


What is n = 2?

100

Casting int into a double adds a decimal

True

100

What does Math.PI return?

What is the value of Pi (estimated)?

100

What is the % symbol called?

What is mod or modulus?

200

89 % ( 5 + 5 ) % 5

What is 4?

200

What is the value of m after the code is executed?

int n = 3;

int m = n;

n--;

m++;

What is m = 4?
200

Truncation is rounding

What is False?

Truncation only cuts off the decimal place of a number

200

What will Math.pow(a,b) return?

What is ab?

200

What does != mean?

What is not equal to?

300

(double) (27/7) where 27 and 7 are ints

What is 3.0?

300


double x = 4.0 / 8.0;

int y = 4 / 8;

double ans = x + y;

System.out.println(ans);


What is 0.5?

300

A Scanner is a method

What is False?

A Scanner is an object

300

What will Math.random() return?

What is a random double between 0 and 1?

300

System.out.println and System.out.print are different for what reason?

What is println adds a line but print doesn't?

println outputs text, sends cursor to next line

print outputs text, keeps cursor on same line


400

Math.pow( (5-2), 3)

What is 27.0?

400

int x = 4;

int y = 5;

double z = 0.5;

String word = “cheese”;

System.out.println(x+y+word);

What is 9cheese?

400

There are 8 primitive types in Java

What is True? 

(boolean, char, byte, short, int, long, float, double)

400

What will Math.max(x,y) return?

What is the higher value of x and y?

400

A variable MUST start with what?

What is a letter or a $?

500

(1-9) % 3

What is -2?

500

System.out.println((int)(Math.abs(-1) * Math.sqrt(9)));

What is 3?

Math.abs(-1) will return 1 and when multiplied by Math.sqrt(9) which is 3.0, the answer will be 3, which is casted into an int, so 3.

500

While loops are the same as do while loops

What is False?

While loops check for the condition BEFORE executing the code but do while loops check the condition AFTER executing the code for the first time

500

How do you have Math.random() choose a double between 1.0 and 10.0? 

What is multiply Math.random() by 9 and add 1?

Math.random() chooses a double from 0.0 to 1.0 so if we multiply by 9 it will choose from 0.0 to 9.0. We then add 1 so that it chooses from 1.0 to 10.0.

500

What is the main method?

public static void main(String [] args) {}

you should try to memorize this one :)

M
e
n
u