Question

In: Computer Science

Create a Java application NumberLoops to practice loops. The draft has one loop to calculate a...

Create a Java application NumberLoops to practice loops. The draft has one loop to calculate a product and the final will add another loop to print integers in a required format. There is no starter code for the problem.

Use a Scanner to input an integer then compute and display the product of all positive integers that are less than the input number and multiple of 3. If no numbers satisfy the conditions, then print out 1 for the product.

Use a double for the product to avoid overflow and print out it without any decimal digits using the format specifier “%.0f”. Numbers 1 and 3 are allowed for the draft and will not be considered as magic numbers.

After printing out the product, enter another integer then print out all non-negative integers less than the input integer, starting with 0. Print one space after each integer and one additional space before an integer if it is less than 10. Print 10 integers per row, except the last row which may have less than 10 integers. In addition to 1 and 3, numbers 9 and 10 are allowed for the final and will not be considered as magic numbers.

The remainder operator (%) will help you here to decide when to call println() to go to the next line. Use only one loop. Do not use nested loops.

Sample run Enter an integer: 36

The product is 7071141369600.

Enter another integer: 36

0 1 2 3 4 5 6 7 8 9

10 11 12 13 14 15 16 17 18 19

20 21 22 23 24 25 26 27 28 29

30 31 32 33 34 35

CODE CHECK:

Solutions

Expert Solution

import java.util.Scanner;
public class NumberLoops
{
   public static void main(String[] args) {
   Scanner scan = new Scanner(System.in);
   System.out.print("Enter an integer: ");
   int num = scan.nextInt();
   int i;
   double product=1;
   for(i=1;i<36;i++)
   {
   if(i%3==0){
   product=product*i;
   }
   }
   System.out.printf("The product is "+"%.0f",product,".");
   System.out.printf("\n");
  
   System.out.print("Enter another integer: ");
   int num2 = scan.nextInt();
   System.out.print("0 ");
   for(i=1;i<num2;i++)
   {
   if (i%10 == 0){
   System.out.print("\n");}
   System.out.print(i+" ");
  
   }
  
      
   }
}

OUTPUT:-


Related Solutions

Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Create in java an interactive GUI application program that will prompt the user to use one...
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students” On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user...
Your task is to create a Java application that converts a specified amount of one currency...
Your task is to create a Java application that converts a specified amount of one currency into another currency for a user. The application must meet the following requirements: Upon execution, the application shall display a brief welcome message announcing that the user is running the currency converter application. The application shall allow a user to convert amounts between any two of the following currencies: United States Dollars (USD), British Pounds (GBP), Swiss Francs (CHF), and Indian Rupees (INR). The...
This is in Java 1. Create an application called registrar that has the following classes: a....
This is in Java 1. Create an application called registrar that has the following classes: a. A student class that minimally stores the following data fields for a student:  Name  Student id number  Number of credits  Total grade points earned             And this class should also be provides the following methods:  A constructor that initializes the name and id fields  A method that returns the student name field  A method that returns the student...
java code Question 4: Iterating with loops You can process the list using a For loop....
java code Question 4: Iterating with loops You can process the list using a For loop. The variable in the For loop becomes the index value for each of the items in the loop. Everything you do to an element inside the loop gets done for the entire list. Examine the following loops. Then use what you know to write the following loops. int[] numbers = new int[100]; for(int i = 0; i < numbers.length; i++){ numbers[i] = i; }...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls:...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls: A Label control with the following text displayed: "First Number:" A Label control with the following text displayed: "Second Number:" An empty TextField control beside the First Number label. An empty TextField control beside the Second Number label. Five buttons: Button 1 labeled + Button 2 labeled - Button 3 labeled * Button 4 labeled / Button 5 labeled = An empty Label control...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java application. Given a set of events, choose the resulting programming actions. Understand the principles behind Java. Understand the basic principles of object-oriented programming including classes and inheritance. Deliverables .java files as requested below. Requirements Create all the panels. Create the navigation between them. Start navigation via the intro screen. The user makes a confirmation to enter the main panel. The user goes to the...
Trying to complete this in Java. Application called 'Coffee Shop' that uses a while loop to...
Trying to complete this in Java. Application called 'Coffee Shop' that uses a while loop to build a customer order. The Coffee Shops sells: Coffee ($3.25), Espresso ($4.25), and Tea ($2.75). The coffee selection presents the customer with the choices of iced (no charge), cream (50 cents), and sugar (50 cents). The espresso selection presents the customer with choice of caramel (no charge) and chocolate (no charge) with one shot (no charge) or two shots ($1.25) of espresso. Once the...
Create a draft project schedule of application of "remote patient monitoring devices in health care" to...
Create a draft project schedule of application of "remote patient monitoring devices in health care" to chronic disease management. This schedule will include all of the identified work activities, the logical predecessor successor relationships, and time estimates for each. It is considered a draft at this point as it will not yet include resources, nor will it necessarily meet the time desires of the client. It will include identifying the critical path and all float. The schedule will be shown...
Create a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
JAVACreate a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT