首页 > 试题广场 >

单组_A+B

[编程题]单组_A+B
  • 热度指数:35295 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
给定两个整数 ab ,请你求出 a+b 的值。

输入描述:
第一行有两个整数 a\ (\ 1 \leq a \leq 10^9\ )b\ (\ 1 \leq b \leq 10^9\ )


输出描述:
输出一个整数,代表 a+b 的值。
示例1

输入

1 2

输出

3
public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       int a = scanner.nextInt();
       int b = scanner.nextInt();
        int sum =a+b;
       System.out.println(sum);
       
    }
发表于 2024-12-25 16:04:28 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            if (in.hasNext()) {
                int b = in.nextInt();
                System.out.println(a + b);
            }
        }
    }
}
发表于 2024-11-19 14:56:48 回复(0)