Answer to Question #253678 in Java | JSP | JSF for leo

Question #253678

Create a for loop program that prompts a user for two integers. If the second integer is greater than the first one, your program should then display multiples of the first integer up till the product of the two entered values. If the second integer is smaller than the first, your program displays error.

Sample Run 1   Enter integer1: 2   Enter integer2: 5  Output 1: multiples = 2 4 6 8 10                        




1
Expert's answer
2021-10-22T06:36:56-0400
import java.util.Scanner;


public class App {
	/**
	 * The start point of the program
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		// prompts a user for two integers.
		System.out.print("Enter integer1: ");
		int integer1 = keyBoard.nextInt();
		System.out.print("Enter integer2: ");
		int integer2 = keyBoard.nextInt();
		// If the second integer is greater than the first one, your program should then
		// display multiples of the first integer up till the product of the two entered
		// values. If the second integer is smaller than the first, your program
		// displays error.
		if (integer2 > integer1) {
			System.out.print("multiples = ");
			for (int i = integer1; i <= integer2; i++) {
				System.out.print((i * 2) + " ");
			}
		} else {
			System.out.println("Error: the second integer is smaller than the first.");
		}
		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS