Java字符串和拆分


Java字符串和拆分

import java.util.Arrays;



public class CountingHighestNumber {

   public static void main(String args[]) {

      int count = 0;

      String str = "2 3 4 3 8 8 3 5 2 6 8";

      String[] strArray = str.trim().split(" ");

      int size = strArray.length;

      int[] intArray = new int[size];



      for(int i = 0; i<size; i++) {

         intArray[i] = Integer.parseInt(strArray[i]);

      }

      System.out.println("Integer Array ::"+Arrays.toString(intArray));

      Arrays.sort(intArray);

      System.out.println("sorted Array ::"+Arrays.toString(intArray));

      int max = intArray[size-1];

      System.out.println("Max value is :"+max);



      for(int i = 0; i<size; i++) {

         if(intArray[i]==max) {

            count++;

         }

      }

      System.out.println("Number of times the largest value repeated is ::"+count);

   }

}