-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoop.java
More file actions
36 lines (30 loc) · 1.3 KB
/
Loop.java
File metadata and controls
36 lines (30 loc) · 1.3 KB
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
36
/*
Date: 21-JAN-2020
Programmer: Dan Hopp
Description: Modify the program from Problem 1 to do the following:
Prompt the user to enter two numbers (integers).
Use these numbers instead of 5 and 6 in Problem 1. So for example, if the
user enters 11 and 38 your program should print out all numbers between 1
and 200 that are divisible by 11 OR 38 (but not both).
*/
package lab01;
import java.util.Scanner;
public class Hopp_prog2 {
public static void main(String[] args){
//Prompt the user to enter two numbers (integers)
Scanner input = new Scanner(System.in);
System.out.print("Please input two integers: ");
int userInput1 = input.nextInt();
int userInput2 = input.nextInt();
//Print all numbers between 1 and 200 that are divisible by the two
//integers the user submitted, but not divisible by both
System.out.println("The following numbers between 1 and 200 are "
+ "divisible by " + userInput1 + " or by " + userInput2 +
", but not by both " + userInput1 + " AND " + userInput2 + ":");
for(int i = 1; i <= 200 ; i++){
if(i % userInput1 == 0 ^ i % userInput2 == 0){
System.out.println(i);
}
}
}
}