1.题目描述
输入给出一个数字N,要求输出N个"Hello SUST!"(不包含双引号)。
输入
输入数据只有单个测试样例,每个输入只有一个正整数N(0 <= N <= 100),占一行。
输出
输出N个“Hello SUST!”(不包含双引号)。
样例输入
3
样例输出
Hello SUST! Hello SUST! Hello SUST!
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
for (int x=0;x<n;x++){
System.out.println("Hello SUST!");
}
}
}
}
2.题目描述
计算A+B。
输入
有多组输入样例,你需要处理到文件末尾。
每行给定两个整数A B( -1000 <= A,B <= 1000)。
输出
对于每个测试样例,输出一个整数(A+B),每个输出占一行。
样例输入
-1 1 2 4 7 9 -1000 1000
样例输出
0 6 16 0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int[] arr = {sc.nextInt(), sc.nextInt()};
System.out.println(arr[0] + arr[1]);
}
}
}
3.题目描述
给定一个正整数N,你需要计算1+2+3+...+N。
输入
有多组测试数据,当输入N=0时结束且对N=0的情况不需要做任何输出。
每个输入样例占一行,每行输入一个正整数N(0 <= N <= 100)。
输出
对于每个输入样例输出一个累加和,每个输出占一行。
样例输入
1 2 4 10 0
样例输出
1 3 10 55
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
ArrayList<Integer> arrayList=new ArrayList<>() ;
int n=1;
while(n!=0){
n=sc.nextInt();
int sum=0;
for(int x=1;x<=n;x++){
sum+=x;
}
arrayList.add(sum);
}
for (int x=0;x<arrayList.size()-1;x++){
System.out.println(arrayList.get(x));
}
}
}