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...
Goals Practice loops and conditional statements Description Create a game for elementary school students to practice...
Goals Practice loops and conditional statements Description Create a game for elementary school students to practice multiplication. The application should display a greeting followed by a set of mathematical questions.  In each set the player is asked to enter a number from 1 to 9 to test multiplication skills or to press ‘E’ to exit the game.  The application checks if the number entered is indeed between 1 and 9 and if not displays a message inviting the...
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...
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: 1. Upon execution, the application shall display a brief welcome message to the user to let her know she is running the currency converter application. 2. 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...
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 Create a program that uses a nested for loop to display a rectangle of...
IN JAVA Create a program that uses a nested for loop to display a rectangle of #'s with a given number of rows and columns,. This should only display the # when the column is an odd number (see examples below). Get the number of rows and columns from the user, and display the result. Examples: If the user provided rows=4, and columns=7, the program should display a pattern as follows: # # # # # # # # #...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT