首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >递归方法在main中不起作用,为什么?

递归方法在main中不起作用,为什么?
EN

Stack Overflow用户
提问于 2021-03-29 08:55:37
回答 1查看 29关注 0票数 0

我想知道为什么递归方法Question();不能在main中运行?Eclipse中的error方法显示“方法问题(Int)不适用于参数()”。我的Doesn()方法不会产生参数(int)吗?抱歉,如果这是混乱,我将保持鹰眼在这一板,并协助任何有关我的程序澄清的问题。

代码语言:javascript
复制
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();
    }
EN

回答 1

Stack Overflow用户

发布于 2021-03-29 09:10:33

导入java.util.*;

公共类Program9Recursion {

代码语言:javascript
复制
//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);
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66847572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档