Write at most two lines of code to generate a random double
and store it in a variable named bankBalance
.
What is the largest, signed value that can be stored in a 2-byte integer? You do not need to reduce your answer. Be certain to show your work, and also very clearly circle your answer!
What does the following code print?
Be certain to show your work, and also very clearly circle your answer!
public class IncrementorExercise {
public static void main(String[] args) {
int e = 2;
int f = 4;
System.out.println(++f + e-- + e-- + f++ + --e - ++f);
System.out.println(e);
System.out.println(f);
}
}
Write the public method numberChecker
which, given a positive integer n
prints all of the even numbers less than n
and returns how many numbers less than n
are divisible by 3.
Hint: Recall that the modulus operator (%
) is used to the get the remainder of a division operation.
Consider the following examples:
numberChecker(10)
returns 3 (because there are 3 numbers less than 10 that are divisible by three: 3, 6, and 9).2
4
6
8
because those are all of the even numbers less than 10.
numberChecker(15)
returns 4 (because the numbers less than 15 that are divisible by three are 3, 6, 9, and 12).2
4
6
8
10
12
14