java - Java中的二项式在获取用户输入后将2个变量保存在一个变量中
问题描述
我尝试在迭代后保存两个用户输入,但我不知道该怎么做。我总是得到
java:19: error: variable x might not have been initialized
long resalt = bio(x, y);
源代码:
import java.util.Scanner;
public class Aufgabe11 {
public static void main (String [] args) {
Scanner pit = new Scanner(System.in);
System.out.println("Enter fac number");
long a = pit.nextLong();
long result = recFac(a);
System.out.println("The factorial of" + " "+ a + " " + "is"+ " " + result);
Scanner pat = new Scanner(System.in);
long[] vars = new long [2];
for(int i = 0; i < vars.length; i++){
System.out.println("Enter bio var:");
vars [i] = pat.nextLong();
}
long x,y = pat.nextLong();
long resalt = bio(x, y);
System.out.println("The bio of" + " " + x + "over" + y + "is" + " " + resalt);
}
public static long recFac (long a) {
if (a <= 1) {
return 1;
}
else {
return a * recFac (a-1);
}
}
public static long bio (long x, long y) {
if ((x == y) || (y == 0))
return 1;
else
return bio (x-1, y) + bio (x-1, y-1);
}
}
解决方案
推荐阅读
- bash - 防止在 AZ CLI ARM 模板部署的参数中转义反斜杠
- flutter - Flutter 如何使用 SliverToBoxAdapter 添加 tabbarview?
- java - 如何使用 REST-Assured 测试相关键值对的根数组?
- android - OpenCV for Android 通过 Visual Studio 到 Unity
- facebook - 如何正确包含 AdMob Facebook Audience Network 适配器?
- c++ - 为什么有些库使用非常量 char * 作为函数参数?
- javascript - 猫头鹰轮播上的图像在移动设备上被放大,我如何更改它以便它在移动设备上显示所有图像?
- javascript - 仅加载 safari 时动态内容移动到中间的页面
- mysql - 使用 SQL 同时加载多个时间序列
- r - R-Studio 过滤数据