[キーボードから数値ソートを入力]

1527 ワード

import java.util.Scanner;
import java.util.Arrays;

public class SortString{
/*
	 , "," , !
	 JDK :Arrays.sort();
*/  
	private static String[] strArr;
	private static int[] intArr;
//     
    public SortString(){
        sortArray(convert(strArr));
    }
//     ;
    public int[] convert(String[] arr){
        try{
            strArr = arr;
            intArr= new int[strArr.length];
            for(int i=0;i<strArr.length;i++){
                intArr[i] = Integer.parseInt(strArr[i]);
            }
        }catch(NumberFormatException e){
            System.out.print(" , !---");
            System.out.println(e.getMessage());
        }
        return intArr;
    }
//     ;
    public void sortArray(int[] arrs){
        intArr = arrs;
        Arrays.sort(arrs);
        for(int i=0;i<intArr.length;i++){
            System.out.println(intArr[i]);
        }
    }
    
    public static void main(String[] args){
    	while(true){
          System.out.print(" ( , ):");
          Scanner sc = new Scanner(System.in);
          String str = sc.nextLine();
          strArr= str.split(",");
          new SortString();
          System.out.println("--------------------------------");
        }
    }
}