我想知道为什么递归方法Question();不能在main中运行?Eclipse中的error方法显示“方法问题(Int)不适用于参数()”。我的Doesn()方法不会产生参数(int)吗?抱歉,如果这是混乱,我将保持鹰眼在这一板,并协助任何有关我的程序澄清的问题。
import java.util.*;
public class Program9Recursion {
//Scanner in = new Scanner(System.in);
public static void Question(int n) {
Scanner in = new Scanner(System.in);
System.out.println("Please enter a number between 1 and 10: ");
n = in.nextInt();
if ( n>= 1 && n <=10) {
System.out.println("You inuptted " + n);
}else {
System.out.println("Please correctly enter a number between 1 and 10:");
n = in.nextInt();
Question(n);
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Question();
}发布于 2021-03-29 09:10:33
导入java.util.*;
公共类Program9Recursion {
//Scanner in = new Scanner(System.in);
public static void Question(int n) {
Scanner in = new Scanner(System.in);
if ( n>= 1 && n <=10) {
System.out.println("You inuptted " + n);
}
else {
System.out.println("Please correctly enter a number between 1 and 10:");
n = in.nextInt();
Question(n);
}
}
public static void main(String[] args) {
Question(11);
}}
https://stackoverflow.com/questions/66847572
复制相似问题