Questions from Starting Out With Java


Q: Write an if-else statement that assigns 0 to the variable

Write an if-else statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10. Otherwise, it should assign −99 to the variable b and assign 0 to the v...

See Answer

Q: Write nested if statements that perform the following test: If amount1

Write nested if statements that perform the following test: If amount1 is greater than 10 and amount2 is less than 100, display the greater of the two.

See Answer

Q: Write code that tests the variable x to determine whether it is

Write code that tests the variable x to determine whether it is greater than 0. If x is greater than 0, the code should test the variable y to determine whether it is less than 20. If y is less than 2...

See Answer

Q: What will the following program display? public class CheckPoint

What will the following program display? public class CheckPoint { public static void main(String[] args) { int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0;...

See Answer

Q: The following program is used in a bookstore to determine how many

The following program is used in a bookstore to determine how many discount ­coupons a customer gets. Complete the table that appears after the program. import javax.swing.JOptionPane; public class C...

See Answer

Q: The following truth table shows various combinations of the values true and

The following truth table shows various combinations of the values true and false connected by a logical operator. Complete the table by circling T or F to indicate whether the result of such a combin...

See Answer

Q: Assume the variables a = 2, b = 4, and

Assume the variables a = 2, b = 4, and c = 6. Circle the T or F for each of the ­following conditions to indicate whether it is true or false.

See Answer

Q: Write an if statement that displays the message "The number is

Write an if statement that displays the message "The number is valid" if the variable speed is within the range 0 through 200.

See Answer

Q: Write an if statement that displays the message "The number is

Write an if statement that displays the message "The number is not valid" if the variable speed is outside the range 0 through 200.

See Answer

Q: Write an if statement that multiplies payRate by 1.5 if

Write an if statement that multiplies payRate by 1.5 if hours is greater than 40.

See Answer