{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

This preview shows pages 1–2. Sign up to view the full content.

// Lab 4-4 // New_Square_Cube.java - This program prints the numbers 0 through 10 along // with their squares and cubes. // Input: None. // Output: Prints the numbers 0 through 10 along with their squares and cubes. public class New_Square_Cube { public static void main(String args[]) { String head1 = "Number: "; String head2 = "Square: "; String head3 = "Cube: "; int numberCounter; // Number 0 through 10. int square; // Stores the square of a number. int cube; // Stores the cube of a number. System.out.println("Squares and Cubes" + "\n"); numberCounter = 0; // Initialize loop control variable. //while( numberCounter <= 10 ) // Do this 11 times. // { // square = numberCounter * numberCounter; // Calculate square.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
// cube = square * numberCounter; // Calculate cube.
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // System.out.println(head1 + numberCounter); // System.out.println(head2 + square); // System.out.println(head3 + cube); // numberCounter++; // Next number. // } // End of while loop. // Comment out the statements that are part of the while loop. // Rewrite the while loop as a for loop here. for(numberCounter = 0; numberCounter <= 10; numberCounter++) { square = numberCounter * numberCounter; // Calculate square. cube = square * numberCounter; // Calculate cube. System.out.println(head1 + numberCounter); System.out.println(head2 + square); System.out.println(head3 + cube); numberCounter++; // Next number. } System.exit(0); } // End of main() method. } // End of New_Square_Cube class....
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online