Description
1.
- Convert the following if-else code to switch/case:
if (code ==1 || code == 5 || code == 8)
System.out.println(Output A);
else if (code == 2 || code == 3 || code == 7)
System.out.println(Output B);
else if(code ==4 || code == 6) System.out.println(Output C);
else System.out.println(Error)
2. Using the following information, determine how many bushels, gallons, quarts, pints and cups there are in a given number of cups. For example,
4331 cups equals: 33 bushels 6 gallons 2 quarts 1 pints 1 cup
- 1 bushel = 8 gallons
- 1 gallon = 4 quarts
- 1 quart = 2 pints
- 1 pint = 2 cups
3. Convert the following nested for/while loop into a nested while/for loop
for (int i=0; i<10;i=i+2){
System.out.println(“i “+i);
int j=60;
while (j>20){
if (j*i > 100) break;
System.out.println(“i “+i+” j “+j);
j=j/2;
}
}
4. 1.The variables below have been initialized as follows:
double salary = 54239.67;
double tax = 123.765;
String firstName = “John”;
String lastName = “Stevens”;
Print the last two lines of the output below (the column header and variable values) using printf statements to match exactly the starting column, number of columns and decimal places for each variable. Do not use t or filler blanks in your print statements.
11111111112222222222333333333344444444445 DO NOT PRINT THESE COLUMNS NUMBERS
12345678901234567890123456789012345678901234567890 USE THEM TO HELP ALIGN THE OUTPUT
First Name Last Name Salary Tax
John Stevens 54239.67 123.76
6.
- In order to compute the solution to a cubic equation, an intermediate step requires the solving the expression below. Write the expression as a Java statement. Assume the variable a and b are doubles
(see picture for full question