Find the error in each of the following code segments, and explain how to correct it: a)

Question:

Find the error in each of the following code segments, and explain how to correct it: 

a)
    i = 1;
    while (i <= 10);
    ++i;
    }
b)
    for (k = 0.1; k != 1.0; k += 0.1) {
    System.out.println(k);
    }

c)
    switch (n) {
    case 1:
    System.out.println("The number is 1");
    case 2:
    System.out.println("The number is 2");
    break;
    default:
    System.out.println("The number is not 1 or 2");
    break;
    }
d) The following code should print the values 1 to 10:
    n = 1;
    while (n < 10) {
    System.out.println(n++);
    }

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Java How To Program Early Objects

ISBN: 9780134743356

11th Edition

Authors: Paul Deitel, Harvey Deitel

Question Posted: