English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a program to display the cubes of the first 15 postive even numbers in ascending order. Print the values as they are generated inside the loop along with the statement "an even cube is". When the loop is done print the string "After the loop."

2007-06-26 16:03:57 · 1 answers · asked by ZG786 1 in Computers & Internet Programming & Design

1 answers

class MyClass {
public static void main(String[] args) {
for (int i=0; i<15; ++i) {
int c = 2*i+2;
System.out.println("an even cube is " + (c*c*c));
}
System.out.println("after the loop");
}
}

==================
Output:

an even cube is 8
an even cube is 64
an even cube is 216
an even cube is 512
an even cube is 1000
an even cube is 1728
an even cube is 2744
an even cube is 4096
an even cube is 5832
an even cube is 8000
an even cube is 10648
an even cube is 13824
an even cube is 17576
an even cube is 21952
an even cube is 27000
after the loop

2007-06-26 16:07:16 · answer #1 · answered by McFate 7 · 0 0

fedest.com, questions and answers