java输入输出练习

输入输出练习
输入描述:
输入数据有多组, 每行表示一组输入数据。每行不定有n个整数,空格隔开。(1 <= n <= 100)。
输出描述: 每组数据输出求和的结果

输入例子1:
1 2 3
4 5
0 0 0 0 0
输出例子1:
6
9
0


import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
        String[] s = sc.nextLine().split(" ");
         int sum = 0;
            for(int i = 0; i< s.length;i++){
                sum = sum + Integer.parseInt(s[i]);
            }
            System.out.println(sum);
        }
        }
}

输入描述:
输入有两行,第一行n

第二行是n个空格隔开的字符串

输出描述:
输出一行排序后的字符串,空格隔开,无结尾空格

输入例子1:
5
c d a bb e

输出例子1:
a bb c d e

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

		s.nextLine();
		String[] x=s.nextLine().split(" ");
		Arrays.sort(x);
		System.out.println(String.join(" ",x));
}
}

输入描述:
多个测试用例,每个测试用例一行。

每行通过空格隔开,有n个字符,n<100

输出描述:
对于每组测试用例,输出一行排序过的字符串,每个字符串通过空格隔开

输入例子1:
a c bb
f dddd
nowcoder

输出例子1:
a bb c
dddd f
nowcoder

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

		while(s.hasNext()){
			String[] x=s.nextLine().split(" ");
			Arrays.sort(x);
			System.out.println(String.join(" ",x));
        }
        }
}

输入描述:
多个测试用例,每个测试用例一行。
每行通过,隔开,有n个字符,n<100

输出描述:
对于每组用例输出一行排序后的字符串,用’,'隔开,无结尾空格

输入例子1:
a,c,bb
f,dddd
nowcoder

输出例子1:
a,bb,c
dddd,f
nowcoder

import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        while(in.hasNext()){
            String[] s=in.nextLine().split(",");
            Arrays.sort(s);
            System.out.println(String.join(",",s));
        }
    }
}

输入描述:
输入有多组测试用例,每组空格隔开两个整数

输出描述:
对于每组数据输出一行两个整数的和

输入例子1:
1 1

输出例子1:
2

import java.util.*;
 
public class Main{
    public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()){
        System.out.println(sc.nextLong() + sc.nextLong());
    }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值