Programming problem: data standardization processing problem-hebust(Java)

During data processing, the input data is not filtered, and there are some data that does not meet the requirements. The data processing program is required to be written. Data less than 0 will be designated as 0, and data greater than 100 will be designated as 100.

Input format:
Input: All elements occupy one line, separated by spaces between the elements, the elements are all integers, the range is [-300…300]

Output format:
Output: All elements occupy one line, separated by Western commas, and the last element keeps Western comma at the end

Input sample:
Here is a set of input. For example:
-1 10 105

Output sample:
The corresponding output is given here. For example:
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]+",");
            }
        }
	}
}

Guess you like

Origin blog.csdn.net/weixin_51430516/article/details/115102969