CCFCSP 201403-1 相反数(满分题解Java版)

it2022-05-09  36

CCF 考试,一定要刷历年真题。 在提交代码的时候,一定不要把中文注释提交上去了,可能会编译报错。

题目描述 201403-1 相反数 Java题解 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Integer numInteger = scanner.nextInt(); scanner.nextLine(); String numString = scanner.nextLine(); scanner.close(); String[] strings = numString.split(" "); int result = 0; for (int i = 0; i < numInteger; i++) { for (int j = i+1; j < numInteger; j++) { Integer oneNum = Integer.valueOf(strings[i]); Integer twoNum = Integer.valueOf(strings[j]); if (oneNum + twoNum == 0) { result++; } } } System.out.println(result); } }

好啦,祝大家都能学习工作顺利。


最新回复(0)