【(Java)OJ在线编程常见输入输出练习场题解汇总】

题源链接: https://ac.nowcoder.com/acm/contest/5647?from=hr_test#question     


目录

1 A+B(1) 

2 A+B(2)  

3 A+B(3)  

4 A+B(4)  

5 A+B(5) 

6 A+B(6) 

7 A+B(7) 

8 字符串排序(1)

9 字符串排序(2)

10 字符串排序(3)


1 A+B(1) 


   
   
  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main (String[] args){
  4. Scanner sc = new Scanner(System.in);
  5. while(sc.hasNext()){
  6. int a = sc.nextInt();
  7. int b = sc.nextInt();
  8. System.out.println(a+b);
  9. }
  10. }
  11. }

2 A+B(2)  


   
   
  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main (String[] args){
  4. Scanner sc = new Scanner(System.in);
  5. int n = sc.nextInt();
  6. while(n> 0){
  7. int a = sc.nextInt();
  8. int b = sc.nextInt();
  9. System.out.println(a+b);
  10. n--;
  11. }
  12. }
  13. }

3 A+B(3)  


   
   
  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main (String[] args){
  4. Scanner sc = new Scanner(System.in);
  5. while(sc.hasNext()){
  6. int a = sc.nextInt();
  7. int b = sc.nextInt();
  8. if(a== 0 & b== 0) break;
  9. System.out.println(a+b);
  10. }
  11. }
  12. }

4 A+B(4)  


   
   
  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main (String[] args){
  4. Scanner sc = new Scanner(System.in);
  5. int len = sc.nextInt();
  6. while(len!= 0){
  7. int sum = 0;
  8. for ( int i= 0;i<len;i++){
  9. sum = sum + sc.nextInt();
  10. }
  11. len = sc.nextInt();
  12. System.out.println(sum);
  13. }
  14. }
  15. }

5 A+B(5) 


   
   
  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main (String[] args){
  4. Scanner sc = new Scanner(System.in);
  5. int n = Integer.parseInt(sc.nextLine());
  6. while(n> 0){
  7. int sum = 0;
  8. String a = sc.nextLine();
  9. String[] as = a.split( " ");
  10. for( int i= 1;i<as.length;i++){
  11. sum = sum + Integer.parseInt(as[i]);
  12. }
  13. System.out.println(sum);
  14. n--;
  15. }
  16. }
  17. }

6 A+B(6) 


   
   
  1. import java. util. Scanner;
  2. public class Main {
  3. public static void main( String[] args){
  4. Scanner sc = new Scanner( System. in);
  5. while(sc. hasNextLine()){
  6. int sum = 0;
  7. String a = sc. nextLine();
  8. String[] as = a. split( " ");
  9. for(int i= 1;i< as. length;i++){
  10. sum = sum + Integer. parseInt( as[i]);
  11. }
  12. System. out. println(sum);
  13. }
  14. }
  15. }

 

7 A+B(7) 


   
   
  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main (String[] args){
  4. Scanner sc = new Scanner(System.in);
  5. while(sc.hasNextLine()){
  6. int sum = 0;
  7. String a = sc.nextLine();
  8. String[] as = a.split( " ");
  9. for( int i= 0;i<as.length;i++){
  10. sum = sum + Integer.parseInt(as[i]);
  11. }
  12. System.out.println(sum);
  13. }
  14. }
  15. }

 

8 字符串排序(1)


   
   
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class Main {
  4. public static void main (String[] args){
  5. Scanner sc = new Scanner(System.in);
  6. int n = Integer.parseInt(sc.nextLine());
  7. while(sc.hasNextLine()){
  8. String a = sc.nextLine();
  9. String[] as = a.split( " ");
  10. Arrays.sort(as);
  11. for( int i= 0;i<n;i++){
  12. System.out.print(as[i]+ ' ');
  13. }
  14. // System.out.println(as[n-1]);
  15. }
  16. }
  17. }

 

9 字符串排序(2)


   
   
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class Main {
  4. public static void main (String[] args){
  5. Scanner sc = new Scanner(System.in);
  6. while(sc.hasNextLine()){
  7. String a = sc.nextLine();
  8. String[] as = a.split( " ");
  9. Arrays.sort(as);
  10. for( int i= 0;i<as.length;i++){
  11. System.out.print(as[i]+ ' ');
  12. }
  13. System.out.println( "");
  14. }
  15. }
  16. }

 

10 字符串排序(3)


   
   
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class Main {
  4. public static void main (String[] args){
  5. Scanner sc = new Scanner(System.in);
  6. while(sc.hasNextLine()){
  7. String a = sc.nextLine();
  8. String[] as = a.split( ",");
  9. Arrays.sort(as);
  10. for( int i= 0;i<as.length- 1;i++){
  11. System.out.print(as[i]+ ',');
  12. }
  13. System.out.println(as[as.length- 1]);
  14. }
  15. }
  16. }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值