0Dima_0

Useful Array Garbage =)

Oct 7th, 2020 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3.  
  4. public class October_6th_2 { //не забудьте переименовать класс =)
  5.     static public  void main(String[] args){
  6.         String string = new Scanner(System.in).nextLine();
  7.         char[] charArray = new char[string.length()];
  8.         for(int i = 0; i < charArray.length; i ++){
  9.             charArray[i] = string.charAt(i);
  10.         }
  11.         System.out.println("Symbol is: " + findTheMostSymbol(charArray));
  12.     }
  13.  
  14.     static public char findTheMostSymbol(char[] charArray){
  15.         char symbol = '0';
  16.         int count = -1;
  17.         for(char c: charArray){
  18.             int local_count = 0;
  19.             for(int i = 0; i < charArray.length; i++){
  20.                 if(charArray[i] == c){
  21.                     local_count ++;
  22.                 }
  23.             }
  24.             if(local_count > count){
  25.                 count = local_count;
  26.                 symbol = c;
  27.             }
  28.         }
  29.         return symbol;
  30.     }
  31. }
  32.  
Add Comment
Please, Sign In to add comment