编程题:数据的规范化处理问题-hebust(Java)

在进行数据处理时,输入数据未经过滤,存在一些不符合要求的数据 要求编写数据处理程序,小于0的数据一律指定为0,大于100的数据一律指定为100

输入格式:
输入:所有元素占一行,元素之间使用空格分开,元素均为整数,范围【-300…300】

输出格式:
输出:所有元素占一行,元素之间使用西文逗号分开,最后一个元素末尾保留西文逗号

输入样例:
在这里给出一组输入。例如:
-1 10 105

输出样例:
在这里给出相应的输出。例如:
0,10,100,

import java.util.Scanner;

public class Main{
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] str = s.split(" ");
        for (int i = 0; i < str.length; i++) {
    
    
            if (Integer.valueOf(str[i]) < 0){
    
    
                System.out.print(0+",");
            }else if (Integer.valueOf(str[i]) > 100){
    
    
                System.out.print(100+",");
            }else {
    
    
                System.out.print(str[i]+",");
            }
        }
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_51430516/article/details/115102969