牛客网 java oj输入输出

链接
牛客网 java oj输入输出_第1张图片

import java.util.*;
public class OJ {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a+b);
        }
    }
}

牛客网 java oj输入输出_第2张图片

import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i = 0;i < n; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a+b);
        }
    }
}

牛客网 java oj输入输出_第3张图片

import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int a = sc.nextInt();
            int b = sc.nextInt();

            if (a == 0 & b == 0){
                break;
            }
            System.out.println(a+b);
        }
    }
}

牛客网 java oj输入输出_第4张图片

import java.util.*;
public class OJ {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        while((n = sc.nextInt()) != 0){
            int sum = 0;

            for(int i = 0;i<n;i++){
                sum += sc.nextInt();
            }
            System.out.println(sum);

        }
    }
}

输入一行整型数组

public static void main(String[] args){
	
	Scanner sc=new Scanner(System.in);
	  
	String[] nums = null; 
	nums = sc.nextLine().split(" "); 
	int num[]=new int[nums.length];
	for(int i=0;i<num.length;i++){
	num[i]=Integer.valueOf(nums[i]);
	}
}

你可能感兴趣的:(剑指Offer,编程题)