Java 输入 输出
1: 单组输入 a+b sdut 1000
1 import java.util.Scanner; 2 public class Main { 3 public static void main(String args[]){ 4 5 Scanner r = new Scanner(System.in) ; 6 int a = r.nextInt(); 7 int b = r.nextInt(); 8 int c = a + b; 9 System.out.println(c); 10 11 } 12 13 14 } 15 16
2: 多组输入 a+b sdut 1010
1 import java.util.Scanner; 2 public class Main{ 3 4 public static void main(String args[]){ 5 6 7 int a,b; 8 9 Scanner cin = new Scanner(System.in); 10 11 12 while(cin.hasNextInt()){ // 实现多组输入 ,求 a+b的和 13 a = cin.nextInt(); 14 b = cin.nextInt(); 15 System.out.println(a+b) ; 16 } 17 } 18 19 20 21 }
3: 多组输入
http://acm.hdu.edu.cn/showproblem.php?pid=1090
1 import java.util.*; 2 public class Main{ 3 4 public static void main(String args[]){ 5 6 int n,a,b; 7 Scanner cin = new Scanner(System.in) ; 8 9 n = cin.nextInt() ; 10 for(int i = 0;i < n;i++){ 11 12 a = cin.nextInt(); 13 b = cin.nextInt(); 14 System.out.println(a+b) ; 15 16 } 17 18 19 } 20 21 22 23 }
4:hdu 1092 http://acm.hdu.edu.cn/showproblem.php?pid=1092
输入: 4 1 2 3 4 5 1 2 3 4 5 0 输出: 10 15 import java.util.*; public class Main{ public static void main(String args[]){ Scanner cin = new Scanner(System.in) ; while(cin.hasNextInt()){ int n = cin.nextInt(); if(n == 0)break ; int sum = 0 ; for(int i = 0 ; i<n;i++){ sum += cin.nextInt(); } System.out.println(sum) ; } } }
hdu 1096 http://acm.hdu.edu.cn/showproblem.php?pid=1096
View Code
1 import java.util.*; 2 public class Main{ 3 4 public static void main(String args[]){ 5 6 Scanner cin = new Scanner(System.in) ; 7 8 int n = cin.nextInt() ; 9 while(n != 0){ 10 11 int num = cin.nextInt(); 12 int sum = 0 ; 13 for(int i = 0 ; i < num;i++){ 14 15 sum += cin.nextInt(); 16 17 18 } 19 System.out.println(sum) ; 20 n--; 21 if(n != 0) System.out.println() ;// 换行 22 } 23 24 25 26 } 27 28 29 }