-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAll primes between 2 numbers.java
More file actions
45 lines (34 loc) · 1 KB
/
All primes between 2 numbers.java
File metadata and controls
45 lines (34 loc) · 1 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
37
38
39
40
41
42
43
44
45
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class AllPrimesBetween {
private static Scanner input1;
private static Scanner input2;
public static void betweenPrime(int first, int second) {
List<Integer> storage = new ArrayList<Integer>();
int n = first;
for(n = first; n <= second; n++) {
boolean isPrime = true;
for(int divisor = 2; divisor <= second / 2; divisor++) {
if (second % divisor == 0) {
isPrime = false;
}
if (isPrime) {
storage.add(n);
}
}
System.out.println("Here are all the primes between your 2 numbers: " + storage);
}
}
public static void main(String[] args) {
input1 = new Scanner(System.in);
System.out.println("please enter an interger: ");
int firstprime = 0;
firstprime = input1.nextInt();
input2 = new Scanner(System.in);
System.out.println("please enter an interger: ");
int secondprime = 0;
secondprime = input2.nextInt();
betweenPrime(secondprime, firstprime);
}
}