You are on page 1of 2

1.

solution
a) boolean isGood = true;
b) char firstLetter = 'p';
c) int way2 = 89;
d) String name = "Manish";
e) int playerScore = 8976543;
f) double class_ = 4.5;
g) double parents_ = 20.5;
h) String name = "Greg";

2. The main method will print the following to the screen:


The value of z is 17
The value of w is 11
The value of x is now 6
The value of y is now 2
c is true
3. just change the name of the file to UsingOperators.java and copy past the following file in to
it.
public static void main(String[] args) {
int x = 5;
int y = 3;
int z = x + x*y - y;
System.out.println("The value of z is " + z);

int w = ++x + y + y--;


System.out.println("The value of w is " + w);
System.out.println("The value of x is now " + x);
System.out.println("The value of y is now " + y);
boolean a = true;
boolean b = false;
boolean c = ((a && (! (x > y))) && (a || y >x));
System.out.println("c is " + c);
}
4. solution
public class TempConverter {
public static void main(String[] args) {
double celsius = 100;
double fahrenheit = (9.0 / 5.0) * celsius + 32;
System.out.println("Temperature in Fahrenheit: " + fahrenheit);
}
}
5. In the main method of `TempConverter`, the temperature in Fahrenheit is computed using the
given formula and printed to the screen.
Output
Temperature in Fahrenheit: 212.0
6. After setting the `celsius` variable to 100 and compiling and running `TempConverter`, the
correct output should be 212.0. If the output is 132, it suggests that integer division was used
somewhere instead of using floating-point division.
It is output is 212.0 so that means we are correct to use.

You might also like