• October 4th, 2011, 02:01 PM
NewAtJava
I dont know how to write this code I am new to Java and one of the labs is: write a counter-controlled while loop that uses the loop control variable to take on the values 0 through 10 Remember to initialize the loop control variable before the program enters the loop. Here is the half written program that they give you. and you are suppose to write the while part. i just cant figure out how to do it.? Can someone show me how this is done? I would really apprectiate it.

Code Java:

```// DoubleQuadruple.java - This program prints the numbers 0 through 10 along // with these values doubled and quadrupled. // Input: None. // Output: Prints the numbers 0 through 10 along with their doubles and quadruples.   public class DoubleQuadruple { public static void main(String args[]) {   String head1 = "Number: "; String head2 = "Doubled: "; String head3 = "Quadrupled: "; int numberCounter; // Numbers 0 through 10. int doubled; // Stores the double of a number. int quadrupled; // Stores the quadruple of a number. final int NUM_LOOPS = 10; // Constant used to control loop.   // This is the work done in the housekeeping() method System.out.println("0 through 10 doubled and quadrupled" + "\n");   // This is the work done in the detailLoop() method   // Initialize loop control variable. // Write your counter_controlled while loop here. // Calculate double. // Calculate quadruple. System.out.println(head1 + numberCounter); System.out.println(head2 + doubled); System.out.println(head3 + quadrupled); // Next number.   // This is the work done in the endOfJob() method System.exit(0); } // End of main() method.   } // End of DoubleQuadruple class.```
• October 4th, 2011, 02:34 PM
Staticity
Do you understand how to use a While Loop, and what it does? Attempt to write the while loop first, and then I can help you with your logic.
• October 4th, 2011, 03:15 PM
NewAtJava
the while loop variable I initiated was numberCounter=0;
so then I put while( numberCounter<=10){
doubled=numberCounter*2;
then the system out statements
numberCounter++;
end while
• October 4th, 2011, 03:16 PM
kenster421
• October 4th, 2011, 03:21 PM
NewAtJava
in the course im taking they go through the while loops but in this particular problem they want you to use what they have given you not with what i can come up with. and so my problem is figuring out how to use the countercontrol while loop using the information they have already entered.
• October 4th, 2011, 03:28 PM
kenster421
While the counter is less than 10:
double the counter and store it in another variable
quadruple the counter and store that in another variable
print the info
increment the counter by 1
• October 4th, 2011, 03:35 PM
NewAtJava
the while loop variable I initiated was numberCounter=0;
so then I put while( numberCounter<=10){
doubled=numberCounter*2;
then the system out statements
numberCounter++;
end while
im not sure if you read this but I cannot use anymore variables than the ones they have given.
• October 5th, 2011, 02:53 PM
kenster421