hduoj 1089-1096 JAVA

本文介绍了一个简单的Java程序,用于实现两个整数的加法运算。程序通过读取用户输入的两个整数,然后输出它们的和。适用于初学者理解基本的输入输出操作和算术运算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1089

Input

1 5
10 20

Ouput

6
30

import java.util.Scanner;


public class Main {
      public static void main(String args[])
      {
          int a,b;
          Scanner reader=new Scanner(System.in);
          while(reader.hasNext())
          {
              a=reader.nextInt();
              b=reader.nextInt();
              System.out.println(a+b);
          }
         
         
      }
}

1090

Input

2
1 5
10 20

Ouput

6
30

import java.util.Scanner;

public class Main {
      public static void main(String args[])
      {
          int a,b,n,i;
          Scanner reader=new Scanner(System.in);
          n=reader.nextInt();
          for(i=0;i<n;i++)
          {
              a=reader.nextInt();
              b=reader.nextInt();
              System.out.println(a+b);
          }
         
         
      }
}

1091

Input

1 5
10 20
0 0

Ouput

6
30

import java.util.Scanner;

public class Main {
      public static void main(String args[])
      {
          int a,b;
          Scanner reader=new Scanner(System.in);
          
          while(reader.hasNext())
          {
              a=reader.nextInt();
              b=reader.nextInt();
              if(a==0&&b==0)
                  break;
              System.out.println(a+b);
          }
         
      }
}

1092

Input

4 1 2 3 4
5 1 2 3 4 5
0

Ouput

10
15

import java.util.Scanner;

public class Main {
      public static void main(String args[])
      {
          int b,n,sum;
          Scanner reader=new Scanner(System.in);
          while(reader.hasNext())
          {
              sum=0;
              n=reader.nextInt();
              if(n==0)
                  break;
              else
              {
                  for(int i=0;i<n;i++)
                  {
                      b=reader.nextInt();
                      sum+=b;
                  }
                  System.out.println(sum);
              }
          }
      }
}

1093

Input

2
4 1 2 3 4
5 1 2 3 4 5

Ouput

10
15

import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        int a, b, n, sum;
        Scanner reader = new Scanner(System.in);
        n = reader.nextInt();
        for (int j = 0; j < n; j++) {
            a = reader.nextInt();
            sum = 0;
            for (int i = 0; i < a; i++) {
                b = reader.nextInt();
                sum += b;
            }
            System.out.println(sum);
        }
    }
}

1094

Input

4 1 2 3 4
5 1 2 3 4 5

Ouput

10
15

import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        int a, b, n, sum;
        Scanner reader = new Scanner(System.in);
        while(reader.hasNext()) { 
            a = reader.nextInt();
            sum = 0;
            for (int i = 0; i < a; i++) {
                b = reader.nextInt();
                sum += b;
            }
            System.out.println(sum);
        }
    }
}

1095

Input

1 5
10 20

Ouput

6

30
 

import java.util.Scanner;

public class Main{
    public static void main(String args[]) {
        int a, b, n, sum;
        Scanner reader = new Scanner(System.in);
        while(reader.hasNext()) { 
            a = reader.nextInt();
            b = reader.nextInt();
            System.out.println(a+b);
            System.out.println();
        }
    }
}

1096

Input

3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3

Ouput

10

15

6

import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        int a, b, n, sum;
        Scanner reader = new Scanner(System.in);
        while (reader.hasNext()) {
            n = reader.nextInt();
            for (int j = 1; j <= n; j++) {
                sum = 0;
                b = reader.nextInt();
                for (int i = 0; i < b; i++) {
                    a = reader.nextInt();
                    sum += a;
                }
                System.out.println(sum);
                if(j!=n)
                  System.out.println();
            }

        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值