In: Computer Science
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.
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.