Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: DoubleQuadruple

Threaded View

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    35
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default DoubleQuadruple

    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.

    // 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.
    Last edited by helloworld922; October 5th, 2011 at 01:48 AM.