CSC 211 -- Java Programming I
Practice Midterm Exam C
Work only 5 out of 6 problems. If you choose problem 1,
answer all three questions.
- Answer the following three questions.
- What is the output produced by the following code
fragment?
int x = 107, y = 0;
while(x > 0)
{
    y++;
    x /= 5;
}
System.out.println(y);
- Rewrite the code fragment in Part 1a using a for loop instead.
- What would happen in Part 1a if the line
while(x > 0)
were changed to
while(x > 0);
- Construct the program trace table and predict the output.
public static void main(String[] args)
{
    int x = 2, y = 7;
    String a = "abc";
    while(x + y < 100)
    {
       x += (2 * x + y);
       y += (x + 2 * y);
       a = y + a;
       if(x + y > 50)
          a = a + x;
    }
    System.out.println(x + " " + y + " " + a);
}
- Write a Java program that will input an amount in Francs and
output the amount in Marks. Assume the exchange rate 6.5 Francs
per Dollar and 2.1 Marks per Dollar.
- Write a Java program that will input (i) the number of hours
worked and (ii) the hourly wage. It should output the total pay
for that person, which is calculated as follows: hourly wage times
number of hours up to 40 plus 1.5 times hourly wage times
number of hours over 40.
- Write a Java program that will input a list of nonnegative
integers. (Stop when a negative integer is entered.) Output the
largest odd integer and the largest even integer.