-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSieveOfEratosthenes.java
More file actions
30 lines (30 loc) · 885 Bytes
/
SieveOfEratosthenes.java
File metadata and controls
30 lines (30 loc) · 885 Bytes
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
import java.util.Scanner;
public class SieveOfEratosthenes {
public static void main(String[] args) {
int userInput = 0;
boolean userHasNotInputted = false;
Scanner inputScanner = new Scanner( System.in);
Eratosthenes primeSorter = new Eratosthenes();
System.out.print("Enter int >= 2:");
while(!userHasNotInputted ) {
if( inputScanner. hasNextInt())
{
userInput = inputScanner. nextInt();
if( userInput >= 2)
{
userHasNotInputted = true;
}
}
else
{
System.out.println("Sorry, this input isn't correct");
System.out.print("Enter int >= 2:");
inputScanner = new Scanner( System.in);
}
}
inputScanner.close();
int[] mainSequence = primeSorter.sieve(userInput);
String primeString = primeSorter.nonCrossedOutSubseqToString(mainSequence) ;
System.out.print( primeString);
}
}