问题是打印以下系列:(a+(2^0)*b), ((a+(2^0)*b)+(a+(2^1)*b)), ((a+(2^0)*b)+(a+(2^1)*b)+(a+(2^2)*b)...+(a+(2^(n-1))*b))a、b、n 和 t 的值由用户输入。't' 表示用户想要计算的系列数。例如,如果 t=2,则用户可以给出 a、b 和 n 的两个单独输入并获得两个不同的系列。if t=2 a=0,b=2,n=10而对于第二个系列——a=5,b=3,n=5输出应该是:2 6 14 30 62 126 254 510 1022 2046 (1st series) 8 14 26 50 98 (2nd series) 下面的程序没有显示所需的输出。有人可以指出错误吗?import java.io.*; class Solution{ public static void main(String []argh){ Scanner in = new Scanner(System.in); int t=in.nextInt(); int s=0; for(int i=0;i<t;i++){ int a = in.nextInt(); int b = in.nextInt(); int n = in.nextInt(); for(int j=0;j<n;j++) { s = s+(a+(2^j)*b); System.out.print(s+" "); } } in.close(); } }
添加回答
举报
0/150
提交
取消