-4
私はJavaの到達不能なコードでエラーメッセージが表示され続けます。ここに私のコードです:私はこのエラーメッセージに到達できないコードを取得し続けています、なぜですか?ここに私のコード
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n;
int product;
System.out.println("Welcome to the Factorial Calculator!");
Object response;
do {
System.out.print("Enter an integer that's greater than 0 but less than 10:");
n = input.nextInt();
product = fact(n);
System.out.println("The factorial of " + n);
System.out.println("is " + product);
System.out.print("Continue?(y/n): ");
response = input.next();
} while (response.equals("y") || response.equals("Y"));
}
public static int fact(int n) {
if (n == 1) {
return 1;
} else
return n * fact(n - 1);
for (int i = 0; i < 10; i++) {
int result = result * i;
int random = (int) (Math.random() * 10);
if (random > 10) {
System.out.println("invalid value - continue loop!");
continue;
// continue executing loop until the application ends
}
System.out.println(random);
}
}
}
} // This curly brace is where I keep getting the error code
'if-else'の後ろに' for'ループがあり、両方が返されます。その 'for'ループに到達できません。別の方法でなければならないのでしょうか? –
あなたは余分な '}'を持っています。 – bcsb1001