
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
![Using a for Loop
NewMultiply.java
1 // NewMultiply.java - This program prints the numbers 0 through 10 along
2 // with these values multiplied by 2 and by 10.
3 // Input: None.
4 |/ Output: Prints the numbers 0 through 10 along with their values multiplied by 2 and by 10.
Summary
In this lab the completed program should print the
5
numbers O through 10, along with their values multiplied
by 2 and by 10. You should accomplish this using a for
7 public class NewMultiply
8 {
loop instead of a counter-controlled while loop.
public static void main(String args[])
{
10
Instructions
11
12
String headl = "Number: ";
1. Write a for loop that uses the loop control variable
13
String head2 = "Multiplied by 2: ";
14
String head3 = "Multiplied by 10: ";
to take on the values 0 through 10.
// Numbers 0 through 10.
// Stores the number multiplied by 10.
// Stores the number multiplied by 2.
final int NUM_LOOPS = 10; // Constant used to control loop.
15
int numberCounter;
2. In the body of the loop, multiply the value of the loop
16
int byTen;
17
int byTwo;
control variable by 2 and by 10.
18
3. Execute the program. Is the output the same?
19
// This is the work done in the housekeeping() method
System.out.println("0 through 10 multiplied by 2 and by 10" + "\n");
20
21
Grading
22
// This is the work done in the detailLoop() method
// Write for loop
23
When you have completed your program, click the Submit
24
button to record your score.
25
26
// This is the work done in the endOf Job() method
System.exit(®);
} // End of main() method.
27
28
29
30 } // End of NewMultiply class.
31](https://content.bartleby.com/qna-images/question/862c34ee-e27f-46b4-a2d2-ab5f4ef78243/6b73d12b-1f4e-4969-983c-f71ec54b5ffb/3tsoey_thumbnail.png)
Transcribed Image Text:Using a for Loop
NewMultiply.java
1 // NewMultiply.java - This program prints the numbers 0 through 10 along
2 // with these values multiplied by 2 and by 10.
3 // Input: None.
4 |/ Output: Prints the numbers 0 through 10 along with their values multiplied by 2 and by 10.
Summary
In this lab the completed program should print the
5
numbers O through 10, along with their values multiplied
by 2 and by 10. You should accomplish this using a for
7 public class NewMultiply
8 {
loop instead of a counter-controlled while loop.
public static void main(String args[])
{
10
Instructions
11
12
String headl = "Number: ";
1. Write a for loop that uses the loop control variable
13
String head2 = "Multiplied by 2: ";
14
String head3 = "Multiplied by 10: ";
to take on the values 0 through 10.
// Numbers 0 through 10.
// Stores the number multiplied by 10.
// Stores the number multiplied by 2.
final int NUM_LOOPS = 10; // Constant used to control loop.
15
int numberCounter;
2. In the body of the loop, multiply the value of the loop
16
int byTen;
17
int byTwo;
control variable by 2 and by 10.
18
3. Execute the program. Is the output the same?
19
// This is the work done in the housekeeping() method
System.out.println("0 through 10 multiplied by 2 and by 10" + "\n");
20
21
Grading
22
// This is the work done in the detailLoop() method
// Write for loop
23
When you have completed your program, click the Submit
24
button to record your score.
25
26
// This is the work done in the endOf Job() method
System.exit(®);
} // End of main() method.
27
28
29
30 } // End of NewMultiply class.
31
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- public class Course{String name;String dept;int number;public Course (String n, String d, int n){name = n;dept = d;number = n;}public String toString(){return "Course " + name + " in " + dept + " #: " + number;}public static void main (String [] args){Scanner in = new Scanner(System.in);add 10 lines using the scanner and saving them as strings The input for each line will be entered a String, a space, another String, and an int. Parse the input string into those three items and make an instance of Course. Add the new Course instance to a generic ArrayList of Course. print out each Course in the ArrayList.arrow_forwardclass Main { // this function will return the number elements in the given range public static int getCountInRange(int[] array, int lower, int upper) { int count = 0; // to count the numbers // this loop will count the numbers in the range for (int i = 0; i < array.length; i++) { // if element is in the range if (array[i] >= lower && array[i] <= upper) count++; } return count; } public static void main(String[] args) { // array int array[] = {1,2,3,4,5,6,7,8,9,0}; // ower and upper range int lower = 1, upper = 9; // throwing an exception…arrow_forwardPrimeAA.java Write a program that will tell a user if their number is prime or not. Your code will need to run in a loop (possibly many loops) so that the user can continue to check numbers. A prime is a number that is only divisible by itself and the number 1. This means your code should loop through each value between 1 and the number entered to see if it’s a divisor. If you only check for a small handful of numbers (such as 2, 3, and 5), you will lose most of the credit for this project. Include a try/catch to catch input mismatches and include a custom exception to catch negative values. If the user enters 0, the program should end. Not only will you tell the user if their number is prime or not, you must also print the divisors to the screen (if they exist) on the same line as shown below AND give a count of how many divisors there are. See examples below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output…arrow_forward
- BAGEL FILES import javax.swing.JFrame; public class Bagel{//-----------------------------------------------------------------// Creates and displays the controls for a bagel shop.//-----------------------------------------------------------------public static void main (String[] args){JFrame frame = new JFrame ("Bagel Shop");frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new BagelControls()); frame.pack();frame.setVisible(true);}} import java.awt.*;import java.awt.event.*; import javax.swing.*; public class BagelControls extends JPanel{private JComboBox bagelCombo;private JButton calcButton;private JLabel cost;private double bagelCost;public BagelControls(){String[] types = {"Make A Selection...", "Plain","Asiago Cheese", "Cranberry"};bagelCombo = new JComboBox(types);calcButton = new JButton("Calc");cost = new JLabel("Cost = " + bagelCost);setPreferredSize (new Dimension (400,…arrow_forwardDo in Java language, filename wealth.javaarrow_forwardfor the class ArrayAverage write a code that calculates the average of the listed numbers with a double result for the class ArrayAverageTester write a for each loop and print out the resultarrow_forward
- Understanding ifStatements Summary In this lab, you complete a prewritten Java program for a carpenter who creates personalized house signs. The program is supposed to compute the price of any sign a customer orders, based on the following facts: The charge for all signs is a minimum of $35.00. The first five letters or numbers are included in the minimum charge; there is a $4 charge for each additional character. If the sign is made of oak, add $20.00. No charge is added for pine. Black or white characters are included in the minimum charge; there is an additional $15 charge for gold-leaf lettering. Instructions 1. Ensure the file named HouseSign.java is open. 2. You need to declare variables for the following, and initialize them where specified: A variable for the cost of the sign initialized to 0.00 (charge). A variable for the number of characters initialized to 8 (numChars). A variable for the color of the characters initialized to "gold" (color). A variable for the…arrow_forwardJAVA Write a program that plays a number-guessing game to guess a secret number randomly generated within the range 1 and 10. The user will get as many numbers of tries as he/she needs to guess the number. Tell the users if their guess is right or wrong and if their guess is wrong let them try to guess the number again. You have solved a similar problem in a previous lab using a while loop. You must generate the secret number using the Java Random class. When the user guesses a number he/she will have to take an input of his guessed number from the keyboard. The user will have to take as many inputs as needed to guess the correct secret-number. That means the code will keep looping as long as the guess is different from the secret number. You also need to count the number of tries and report the count at the end. Use a do-while loop to prompt the user to guess again if the guess is wrong. Make sure that it doesn't mess up the output if you guess the secret number on the first try.…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education