lab4-4 - // System.out.println(head1 + numberCounter); //

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

View Full Document Right Arrow Icon
// 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.
Background image of page 1

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

View Full DocumentRight Arrow Icon
// cube = square * numberCounter; // Calculate cube.
Background image of page 2
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 &lt;= 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

This note was uploaded on 04/30/2008 for the course MNGT 3040 taught by Professor Landrum during the Fall '08 term at Auburn University.

Page1 / 2

lab4-4 - // System.out.println(head1 + numberCounter); //

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online