Question

In: Computer Science

Java Program Use for loop 1.) Write a program to display the multiplication table of a...

Java Program

Use for loop

1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15

2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use math function) 1^2 +2^2+....10^2=385

Use Do-while

Write a do-wile loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat, otherwise, it should terminate.

Continue

Write a program that reads an integer and display all the positive ODD numbers from 0 to n (integer entered by the user). Use CONTINUE branching statement to skip the display of EVEN in the result.

Solutions

Expert Solution

import java.util.Scanner;


public class MultiplicationTable {

        
        public static void main(String[] args) {
                Scanner in = new Scanner(System.in);
                
                System.out.println("Enter number whose"
                                + " multiplication table you want: ");
                int n = in.nextInt();
                
                System.out.println("Enter number of terms: ");
                int numTerms = in.nextInt();

                for(int i=1; i<=numTerms; i++) {
                        System.out.println(n + "\t*\t" + i +" \t = " + (n * i));
                }
                
                in.close();
        }

}
**************************************************

Answering your first question, as the questions require different code. I request you to please post single question in a thread, so that it helps us in explaining the things better to you. Hope you understand!

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
Write a java program of a multiplication table of binary numbers using a 2D array of...
Write a java program of a multiplication table of binary numbers using a 2D array of integers.
Meant to be written in Java JDK 14.0 Write a program to display the conversion table...
Meant to be written in Java JDK 14.0 Write a program to display the conversion table from meter to feet using formatted output (printf()): 1 meter = 3.28084 feet; 1 foot = 12 inch When display the number, round the number to 2 decimal places. Set the number in the 1st the 2nd columns to the left align, set the 3rd column to the right align: meter(s) feet inch(es) 1 3.28 37.37 2 x.xx xx.xx 3 x.xx xxx.xx
I want the program to use 1- D array and display a table as output. Write...
I want the program to use 1- D array and display a table as output. Write a script to simulate the rolling of two dice. The script should use Math.random to roll the first die and again to roll the second die. The sum of the two values should then be calculated. [Note: Since each die can show an integer value from 1 to 6, the sum of the values will vary from 2 to 12, with 7 being the...
Write a program in java that deliberately contains an endless or infinite while loop. The loop...
Write a program in java that deliberately contains an endless or infinite while loop. The loop should generate multiplication questions with single-digit random integers. Users can answer the questions and get immediate feedback. After each question, the user should be able to stop the questions and get an overall result. See Example Output. Example Output What is 7 * 6 ? 42 Correct. Nice work! Want more questions y or n ? y What is 8 * 5 ? 40...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move...
Please use Java language with comments! Thanks! Write a program that will display multiple dots move across the Frame and randomly change direction when they hit the edge of the screen. Do this by creating a Dot class and making each dot an object of that class. You may reuse code written in class for this part of the assignment. Create a subclass of the Dot class called PlayerDot that is controlled by the player through keyboard input (arrow keys)...
powers: Write a program to display the following table with headings and totals. You must use...
powers: Write a program to display the following table with headings and totals. You must use variables to represent all quantities and a for loop for repetition.          x       x^2      x^3          11      121      1331          14      196      2744          17      289      4913          20      400      8000          23      529      12167          26      676      17576          29      841      24389          32      1024     32768          35      1225     42875          38      1444     54872 Totals:  245     6745     201635
Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending...
Write a for loop in .java to display all numbers from 13 - 93 inclusive, ending in 3. • Write a for loop to display a string entered by the user backwards.
Write a C program that meets the following requirements. Uses a while loop to display the...
Write a C program that meets the following requirements. Uses a while loop to display the first 10 natural numbers (on one row, with a tab separating each number) Uses a while loop to find the sum of the second set of 10 natural numbers. Reads a user entry and displays all the natural numbers up to the user entry (on a column list with a new line separating each number). Finds and displays the sum of all natural numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT