Question

Loop Lab Using a counter controlled while pro with the In this 51: program should print th the necessary o throu data file contains in lab, you use a completed, the The data files this when d for 10 along their and output statements. Notepad or the text editor of variable declarations values 1. Open the code file med Multiply java using na source LAi your choice. loop that uses the loop variable to take 2 Write a counter-controlled while the loop control variable before the the values 0 through 10 Reme program enters the loop. variable by 2 and by 1 3 In the body of the loop multiply the value of the loop control the body of the op Remember to change the value of the loop control variable in file in a directory of your choice, and then make that directo your working directory. 5. Compile the source code file, Multiply. java. 6 Execute the program. Record the output of this program. sing a Sentinel Value tn

Newmultiply.Java

// NewMultiply.java - This program prints the numbers 0 through 10 along
// with these values multiplied by 2 and by 10.
// Input: None.
// Output: Prints the numbers 0 through 10 along with their values multiplied by 2 and by 10.


public class NewMultiply
{
   public static void main(String args[])
   {
      
       String head1 = "Number: ";
       String head2 = "Multiplied by 2: ";
       String head3 = "Multiplied by 10: ";              
       int numberCounter;    // Numbers 0 through 10.
       int byTen;       // Stores the number multiplied by 10.
       int byTwo;    // Stores the number multiplied by 2.
       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 multiplied by 2 and by 10" + "\n");

       // This is the work done in the detailLoop() method
       // Write for loop
      
       // This is the work done in the endOfJob() method
System.exit(0);
   } // End of main() method.

} // End of NewMultiply class.

NOTE.

Please my teacher needs to see---- Screen Shot of the executed program showing that it worked ( a JPG or such file), and a SOURCE CODE (in a WORD doc or such) and a JAVA file, my source code, PROOF that my program compiles AND PROOF that it PRODUCES the proper OUTPUT. Please have the followingDISPLAYED WITHIN the SOURCE CODE file, near the top (so that he will see it when he print out the file).

My name Hamraj Selemani

class # 705

Lab # 5

PLEASE I NEED SCREEN SHOTS CONTAINING SOURCE CODE, MY NAME(Hamraj selemani), MY CLASS(705) & JAVA FILE.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

While Loop

/*
Here I have initialised loop control variable with 1.
because initializing it to 0 will lead to an infinite loop execution
because 0*2*10=0
so loop will never stop.
*/


public class NewMultiply {

   public static void main(String a[]){
      
       int loopController=1; //loop control variable
      
       while(loopController<10){
           loopController=loopController*2*10;
       }
       System.out.println("Loop control variable: "+loopController);
   }
}

Servers?Console X <terminated> NewMultiply [Java Application] C:LPr Loop control variable: 20

For Loop


public class NewMultiply {

   public static void main(String a[]){
      
       int ans=0;
      
       for(int loopController=0;loopController<10;loopController++){
           loopController=loopController*2*10;
       ans=loopController;
       }
       System.out.println("Loop control variable: "+ans);
   }
}

Output:

Servers Console X <terminateds NewMultiply [Java Application] Loop control variable: 20

Add a comment
Know the answer?
Add Answer to:
Newmultiply.Java // NewMultiply.java - This program prints the numbers 0 through 10 along // with these...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Summary In this lab the completed program should print the numbers 0 through 10, along with...

    Summary In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and by 10. Execute the program and...

  • Can someone help me with this Python code Summary In this lab, you work with the...

    Can someone help me with this Python code Summary In this lab, you work with the same Python program you worked with in Labs 5-1 and 5-3. As in those earlier labs, the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. However, in this lab you should accomplish this using a while loop with a break statement. Instructions Make sure that the file NewestMultiply.py is selected and open. Write...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes methods that require multiple...

    In this lab, you complete a partially written Java program that includes methods that require multiple parameters (arguments). The program prompts the user for two numeric values. Both values should be passed to methods named calculateSum(), calculateDifference(), and calculateProduct(). The methods compute the sum of the two values, the difference between the two values, and the product of the two values. Each method should perform the appropriate computation and display the results. The source code file provided for this lab...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • Write a program that will check a Java file for syntax errors. The program will ask...

    Write a program that will check a Java file for syntax errors. The program will ask for an input-file name and output-file name and will then copy all the code from the Java input file to the Java output file, but with the following changes: 1. Any syntax error found in the Java input file will be corrected: a. Missing semicolon b. Missing compound statements (curly braces) c. All comments have to start with // and end with a period....

  • 4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java...

    4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT