Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
55 lines (42 loc) · 1.3 KB

File metadata and controls

55 lines (42 loc) · 1.3 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
46
47
48
49
50
51
52
53
54
55
/*
* PROJECT: Next Prime Number
* DESCRIPTION: Have the program find prime numbers until the user chooses to stop asking for the next one.
* COMPLETED: 6/15/15
*/
package Numbers;
import java.util.Scanner;
public class NextPrimeNumber {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
//Instantiates boolean to limit prime number to one per enter pressed
boolean findNext=true;
//Instantiates variable to track how many times a number is divisible by another
int count;
//Instantiates variable that the scanner looks for to calculate the next number
String AffirmativeCommand="";
//Startup instructions
System.out.println("Press enter to find the next prime number");
//Checks if user has asked to go on
if (findNext == true){
//For loop for dividend
for (int i = 1; i > 0; i++) {
count = 0;
//For loop for divisor that checks each value for the dividend
for (int j = 1; j < i; j++) {
if (i % j == 0) {
count++;
}
}
//If the dividend is divisible by any divisor the if statement will not run
if (count == 1){
System.out.println(i);
findNext=false;
if(scanner.nextLine().equals(AffirmativeCommand))
findNext=true;
}
}
}else{
scanner.close();
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.