Java Reference
In-Depth Information
System.out.println("This program adds two numbers.");
System.out.print("Would you like to run the program: (Y/y) ");
response = console.next().charAt(0);
System.out.println();
while (response == 'Y' && response == 'y')
{
System.out.print("Enter two numbers: ");
num1 = console.nextInt();
num2 = console.nextInt();
System.out.println();
System.out.printf("%.2f + %.2f = %.2f %n",
num1, num2, (num1 - num2));
System.out.print("Would you like to add again: (Y/y) ");
response = console.next().charAt(0);
System.out.println();
}
}
}
14. What is the output of the following program segment?
int count = 0;
while (count++ < 10)
System.out.println("This loop can repeat statements.");
15. What is the output of the following program segment?
int count = 5;
while (--count > 0)
System.out.print(count + " ");
System.out.println();
16. What is the output of the following program segment?
int count = 5;
while (count-- > 0)
System.out.print(count + " ");
System.out.println();
17. What is the output of the following program segment?
int count = 1;
while (count++ <= 5)
System.out.print((count * (count - 2)) + " ");
System.out.println();
Search WWH ::




Custom Search