我正在創建一個程序,在該程序中它生成的素數達到用戶輸入的特定數字。當我在運行程序時輸入數字時,程序不輸出任何內容,並且仍在運行,我無法弄清楚原因。我試過使用double而不是int,而且我試過使用i ++而不是++,我沒有解決這個問題。有人請幫助!這是我寫的代碼:控制檯Java中沒有輸出
package assignment_4_1;
import java.util.Scanner;
public class Assignment_4_1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("Enter a number above 50 to find all of the primes between 1 and that number: ");
int upto = input.nextInt();
int firstloop = 1;
while(firstloop < upto)
{
for(int i=2; i<=firstloop; ++i)
{
double secondloop;
if(firstloop % i == 0)
{
secondloop = 0;
}
secondloop = 1;
if(secondloop == 1);
{
System.out.println(firstloop);
}
firstloop++;
}
}
}
}
感謝誰能告訴我我做錯了什麼。
也如果有一個語句對'if(secondloop == 1)'不起作用,',如果刪除了分號,下一個塊將有條件地執行,而不是總是執行。 – NESPowerGlove 2014-11-06 14:17:29
@mdl這是我的問題,謝謝你的幫助:) – Garrett 2014-11-06 14:22:50