for
, while
, and do-while
loops, and for(int i = 5; i < 30; i+=5) System.out.println(i);Question 2) What does the following loop output?
int j = 0; while (j <= 8) { System.out.println(++j); // preincrement operator! }Question 3) What does the following loop output?
for (int k = 7; k >= 0; k--); System.out.println(k); // are you sure?Question 4) What does the following loop output?
for (int l = 0; l > 0; l++) System.out.println(l);Question 5) What does the following loop output?
int m = 0; do { System.out.println(m--); // postincrement operator } while (m > 0);Your teaching assistant will discuss the output of each of the loops.
Complete the following tasks and submit to Checkin on the course website when you are finished, automated grading will be running:
public static void reverseString(String s) { // add code here } public static void printAscii(char start, char end) { // add code here } public static double raiseToPower(double number, int exponent) { // add code here }
// Test reverseString String forward = "Java Programming rules!"; System.out.print("Forward string: "); System.out.println(forward); System.out.print("Reverse string: "); reverseString(forward); // Test printAscii System.out.println("ASCII Table"); printAscii('!', '9'); // Test raiseToPower System.out.printf("3.0 to the 5 = %.3f\n", raiseToPower(3.0, 5)); System.out.printf("2.5 to the 2 = %.3f\n", raiseToPower(2.5, 2)); }
Forward string: Java Programming rules! Reverse string: !selur gnimmargorP avaJ ASCII Table 33: ! 34: " 35: # 36: $ 37: % 38: & 39: ' 40: ( 41: ) 42: * 43: + 44: , 45: - 46: . 47: / 48: 0 49: 1 50: 2 51: 3 52: 4 53: 5 54: 6 55: 7 56: 8 57: 9 3.0 to the 5 = 243.000 2.5 to the 2 = 6.250