JAVA の A + B problem(JAVA输入格式)

SDNUOJ1001
while(cin>>a>>b)
{
  cout<<a+b<<endl;
}

import java.io.BufferedInputStream;
import java.util.*;
public class Main {

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

    }

}

SDNUOJ1002
cin>>n;
while(n- -)
{
  cin>>a>>b;
  cout<<a+b<<endl;
}

import java.io.BufferedInputStream;
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        int n;
        n = in.nextInt();
        while(n-- > 0)
        {
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(a + b);
        }

    }

}

SDNUOJ1003
while(cin>>a>>b && (a+b))
{
  cout<<a+b<<endl;
}

import java.io.BufferedInputStream;
import java.util.*;
public class Main {

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

    }

}

SDNUOJ1004
wihile(cin>>n && n)
{
  ans = 0;
  for(int i = 0; i < n; i ++)
  {
  cin>>x[i];
  ans += x[i];
  }
  cout<<ans<<endl;
}

import java.io.BufferedInputStream;
import java.util.*;
public class Main {

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

    }

}

猜你喜欢

转载自blog.csdn.net/wuswi0412/article/details/81253061