에서 "0"으로 루프를 종료하려고 내가 입력하는 사용자가 루프를 종료하기 위해 노력하고있어 0사용자
/*
Natasha Shorrock
Assignment A4
10/20/16
*/
package a4;
import java.util.Scanner;
public class MainApp {
static boolean isPrimeOptimized(int candidate) {
if (candidate < 2) {
return false;
}//if
if (candidate % 2 == 0) {
//divisble by 2 with no remainder
//is not prime
return false;
}//if
int divisor = 3;
while (divisor < candidate/2) {
if (candidate % divisor == 0) {
return false;// this is not prime
}//if
divisor = divisor + 2;
}//while
return true;
}//isPrime
public static void main(String[] args) {
while (true) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 2 numbers or zero to exit: ");
//ask the user for low and high
//range of [prime numbers to generate
int low = sc.nextInt();
int high = sc.nextInt();
int candidate = low;
int count = 0;
while (candidate <= high) {
if (isPrimeOptimized(candidate)) {
//if prime print
count = count + 1;
System.out.println();
System.out.println(count + " " + candidate);
}//if
candidate = candidate + 1;
}//while
}//while (true)
}//class
}//classMainApp
그녀는 하나 개의 번호를 요청, 그래서 그녀는 '0'입력 한 경우 만'low' 채워 것하고 high''을 기다릴 것입니다. 따라서 두 스캔 사이에 if가 있어야하며 '낮음'만 확인해야합니다. –