[英]How to take multiple inputs of integer using scanner and to use for same equation in java to produce different output?
Code:: 码::
package practice;
import java.util.*;
import java.io.*;
public class Practice{
public static void main(String []argh){
Scanner in = new Scanner(System.in);
int s2 = 0,s1=0, res = 0,a=0,b=0,n=0;
a = in.nextInt();
b = in.nextInt();
n = in.nextInt();
if(a>=0 && b<=50){
}
if (n>=1 && n<=15){
for(int j=0;j<=n-1;j++){
int c= (int)Math.pow(2,j);
s1 = c * (b);
s2 = s1+s2;
res = a+s2;
System.out.print(res + " ");
} }
}
//in.close();
}
//}
============================================================================ ================================================== =========================
Input:
输入:
0
0
2
2
10
10
Output:
输出:
2 6 14 30 62 126 254 510 1022 2046
2 6 14 30 62 126 254 510 1022 2046
======================= =======================
I want to ask user how many queries/how many inputs and has to accept the integer values and process output. 我想问用户有多少查询/有多少输入,并且必须接受整数值并处理输出。
Sample Input
样本输入
2
2
0 2 10
0 2 10
5 3 5
5 3 5
Sample Output
样本输出
2 6 14 30 62 126 254 510 1022 2046
2 6 14 30 62 126 254 510 1022 2046
8 14 26 50 98
8 14 26 50 98
扫描程序无需读取3个整数,而是可以读取一行3个数字,并用空格分隔,然后split
字符串split
以填充3个名为整数的变量,然后从那里开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.