File size: 569 Bytes
8389381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
From the given lines of code, form a program that calculates and prints the squares of even numbers.
Your task is to correct the faulty solution above.
The task requires that the lines of code are also correctly indented!



int num = 0;
while (num <= 30) {
  num++;

  // for odd numbers, exit the IF statement and go back to the top of the while loop, to get the next 'num'
  if (num % 2 == 1) {
    continue;
  }

  // for even numbers, calculate the square and print it
  int square = num * num;
  System.out.println("The square of the number is: " + square);
}