hdoj 1089~1096 八道简单A+B问题 (JAVA)

本文提供了几个使用Java实现的基本加法计算器程序示例。这些示例通过读取标准输入中的整数并计算它们的和来演示简单的加法操作。每个程序都展示了不同的输入处理方式,包括单组输入、多组输入以及特定条件下的输入终止。

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

1089
Sample Input
1 5
10 20
Sample Output
6

30

import java.util.*;
import java.math.*;
import java.io.*;
public class Main1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
	int a,b;
	a=in.nextInt();
	b=in.nextInt();
	int c;
	c=a+b;
	System.out.println(c);
}
	}

}

1090
Sample Input
2 1 5 10 20
Sample Output
6 30
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
    int n;
    n=in.nextInt();
    for(int i=0;i<n;i++)
    {
        int a,b;
        a=in.nextInt();
        b=in.nextInt();
        int c;
        c=a+b;
        System.out.println(c);
    }
}
    }

}
1091

1 5 10 20 0 0

Sample Output
6 30
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
    int a,b;
    a=in.nextInt();
    b=in.nextInt();
    if(a==0&&b==0)
    {
        break;
    }
    else
    {
        System.out.println(a+b);
    }
}
    }

}

1092

Sample Input
4 1 2 3 4 5 1 2 3 4 5 0
 

Sample Output
10 15
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n;
while(in.hasNext())
{
    n=in.nextInt();
    if(n!=0)
    {
    int b=0;
for(int i=0;i<n;i++)
{
    int a;
    a=in.nextInt();
    b=b+a;
}
System.out.println(b);
    }
}

    }

}
1093

Sample Input
2 4 1 2 3 4 5 1 2 3 4 5
 

Sample Output
10 15
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n;
n=in.nextInt();
for(int i=0;i<n;i++)
{
    int m;
    m=in.nextInt();
    int b=0;
    for(int c=0;c<m;c++)
    {
        int a;
        a=in.nextInt();
        b=b+a;
    }
    System.out.println(b);
}
    }

}
1094

Sample Input
4 1 2 3 4 5 1 2 3 4 5
 

Sample Output
10 15
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
    int n;
    n=in.nextInt();
    int b=0;
    for(int i=0;i<n;i++)
    {
        int a;
        a=in.nextInt();
        b=b+a;
    }
    System.out.println(b);
}
    }

}
1095

Sample Input
1 5 10 20
 

Sample Output
6 30
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
    int a,b;
    a=in.nextInt();
    b=in.nextInt();
    int c;
    c=a+b;
    System.out.println(c);
    System.out.println( );
}
    }
}
1096

Sample Input
3 4 1 2 3 4 5 1 2 3 4 5 3 1 2 3
 

Sample Output
10 15 6
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
Scanner in =new Scanner(System.in);
while(in.hasNext())
{
    int n;
    n=in.nextInt();
    for(int i=1;i<=n;i++)
    {
        int a;
        a= in.nextInt();
        int c;
        c=0;
        for(int t=0;t<a;t++)
        {
            int b;
            b=in.nextInt();
            c=c+b;
        }
        System.out.println(c);
        if(i!=n)
        {
        System.out.println( );
        }
    }
}
    }
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值