java - 如何在递归 Java 中使用用户输入
问题描述
public static void main(String[] args) {
Scanner play = new Scanner(System.in);
System.out.println("Enter price of shoe 1: ");
int n = play.nextInt();
System.out.println("Enter price of shoe 2: ");
int m = play.nextInt();
calculateShoe(int n, int m);
}
public static int calculateShoe(int n, int m) {
if(n < m) {
System.out.println("Shoe 1 is less than shoe 2.");
}
else {
System.out.println("Your total is: " + n + " and your savings are: " + m);
}
}
}
我在这个程序中得到的唯一错误是回调递归方法。我不知道如何使用用户输入调用程序。
解决方案
你不应该打电话
calculateShoe(int n, int m)
。应该只是calculateShoe(n, m);
同样的返回类型
calculateShoe
应该是void
而不是int
。关闭扫描仪对象
play.close();
而且您发布的代码与递归无关。
推荐阅读
- fs - NodeJS (fs 模块) - 绝对文件路径附加到节点应用程序的 cwd
- keras - 检查输入时出错:预期 time_distributed_136_input 有 5 个维度,但得到了形状为 (16, 128, 128, 3) 的数组
- javascript - 在 JavaScript 中循环数组并使用拼接删除其所有元素?
- asp.net-mvc - 当用户需要更新信息时,Asp.net MVC 4 重定向
- html - 如何在 ReactJS 中的 div 中放置元素?
- amazon-cloudwatch - 如何在 python 用户定义函数中定义 amazon-cloudwatch boto3.client
- java - LibGDX 模型实例颜色未传递给顶点着色器
- r - 使用粘贴在数据集中自动命名
- python - 尝试在 python 中进行标签编码时,ValueError 包含新标签
- opencv3.0 - 使用单应矩阵的 cv2 姿态估计