Java 输入输出用例

1.

.

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        while (scan.hasNext()) {

            int a = scan.nextInt();

            int b = scan.nextInt();

            System.out.println (a+b);

        }  

    }

}


2.

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int pair = sc.nextInt();

        for (int i = 0; i < pair; i++) {

            int a = sc.nextInt();

            int b = sc.nextInt();

            System.out.println(a+b);

        }

    }

}


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);

        }

    }

}


4

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {

            int n = sc.nextInt();

            if (n == 0)

                break;

            int res = 0;

            for (int i = 0; i < n; i++) {

                res += sc.nextInt();

            }

            System.out.println(res);

        }

    }

}



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 subN = sc.nextInt();

            int res = 0;

            for (int j = 0; j < subN; j++) {

                res += sc.nextInt();

            }

            System.out.println(res);

        }

    }

}


6

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()){

            int n = sc.nextInt();

            int res = 0;

            for (int i = 0; i < n; i++) {

                res += sc.nextInt();

            }

            System.out.println(res);

        }

    }

}


7

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {

            String line = sc.nextLine();

            String[] strs = line.split(” “);

            int res = 0;

            for (int i = 0; i < strs.length; i++) {

                res += Integer.valueOf(strs[i]);

            }

            System.out.println(res);

        }

    }

}


8

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.nextLine());

        String line = sc.nextLine();

        String[] strs = line.split(” “);

        Arrays.sort(strs);

        for (String str : strs) {

            System.out.print(str + ” “);

        }

    }

}


9

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while (sc.hasNextLine()) {

            String line = sc.nextLine();

            String[] strs = line.split(” “);

            Arrays.sort(strs);

            for(int i = 0; i < strs.length-1; i++) {

                System.out.print(strs[i] + ” “);

            }

            System.out.println(strs[strs.length-1]);

        }

    }

}


10 

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while (sc.hasNextLine()) {

            String line = sc.nextLine();

            String[] strs = line.split(“,”);

            Arrays.sort(strs);

            for (int i = 0; i < strs.length-1; i++) {

                System.out.print(strs[i] + “,”);

            }

            System.out.println(strs[strs.length-1]);

        }

    }


0 赞 Like

Leave a Reply

Your email address will not be published. Required fields are marked *