Spaces:
Running
Running
| 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); | |
| } | |