-2
我试图通过stdin
来输入,我想要"t"
乘以a
,b
和n
的值。但我得到编译错误该变量可能未被初始化变量a
,b
和n
。为什么我会在for循环中初始化变量时,“变量可能没有初始化变量a,b和n”?
我无法弄清楚我出错的地方。
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
int num;
Scanner in = new Scanner(System.in);
num = in.nextInt();
int sol;
sol= takken(num);
System.out.println(sol);
}
public static int takken(int howManyTimes){
int a, b, n;
int x;
int solution = 0;
Scanner d = new Scanner(System.in);
int y = 4;
for(int j = 0; j< y; j++)
{
a = d.nextInt();
b = d.nextInt();
n = d.nextInt();
}
solution = a;
int temp = 0;
for (int i = 0; i < n; i++){
x = (int) Math.pow(2,i);
temp = x * b;
solution = solution + temp;
}
return solution;
}
}
你是对的。删除我的评论... – Alexander