CS7 Exam 1 Practice Questions

Here are some good problems from the book (JBD) to try:
And here are a few more.  Assume all programs compile correctly (any errors are unintentional) unless stated otherwise.

1.  Determine the output:

class HelloWorld {
public static void main (String[] args) {
int a=0, b=1;
System.out.println(a + " " + b);
a += b*3;
System.out.println(a + " " + b);
--b;
System.out.println(a + " " + b);
System.out.println(a + " " + --b); 
}
}

2.  Determine the output

// assume a 3 is entered when prompted
import tio.*;
class HelloWorld {
public static void main (String[] args) {
String greeting = "Hello";
int num;

System.out.println(greeting + " Please enter a number: ");
num = Console.in.readInt();
if (num < 5)
System.out.print("That is just fine... ");
else
System.out.print("That is a great number... ");
System.out.println("for me to poop on!");
}
}

3.  Write java declarations for the following:

4.  Write a java program that reads in two integers and prints their product, sum, and average.

5.  Write a program that reads a single integer then prints "YES" if the number is even and divisible by 4, and a "NO" otherwise.