import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] nums = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); sum += nums[i]; } System.out.println(sum); } }
import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { // 注意 while 处理多个 case int n = in.nextInt(); in.nextLine(); // 吸收换行符 String[] inp =in.nextLine().split(" "); ArrayList<String> num = new ArrayList<>(Arrays.asList(inp)); System.out.print(num.stream().mapToInt(Integer::parseInt).sum()); } } }
import java.util.Scanner; import java.util.ArrayList; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Integer> array=new ArrayList<Integer>(); while (in.hasNext()) { //int n = in.nextInt(); String s=in.nextLine(); String s1=in.nextLine(); String[] sList=s1.split(" "); int sum=0; for(int i=0;i<sList.length;i++){ sum+=Integer.valueOf(sList[i]); } System.out.print(sum); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] arr = new int[N]; int sum = 0; for (int i = 0; i < N; i++) { arr[i] = sc.nextInt(); sum += arr[i]; } System.out.print(sum); } }
//没用上N怎么办呀 import java.util.Scanner; public class Main { public static void main(String [] args){ Scanner sc = new Scanner(System.in); String m = sc.nextLine(); String s = sc.nextLine(); String [] integer = s.split(" "); Integer sum = 0; for(String i : integer){ sum=sum+Integer.parseInt(i); } System.out.println(sum); } }
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scan1 = new Scanner(System.in); int a=scan1.nextInt(); Scanner scan2 = new Scanner(System.in); int sum=0; if (scan2.hasNext()) { for (int i =0;i<a;i++){ int[] n = new int[a]; n[i]=scan2.nextInt(); sum=sum+n[i]; } System.out.println(sum); } scan1.close(); scan2.close(); } }请问这个为什么不能通过用例呢