Alrarapie

frekuensi_karakter

Dec 5th, 2021
615
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class frekuensi_karakter {
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         String input = sc.nextLine();
  8.         int[] score = new int[95];
  9.         for (int i = 0; i < input.length(); i++) {
  10.             score[(int)input.charAt(i)-' ']++;
  11.         }
  12.         for (int i = 0; i < score.length; i++) {
  13.             char x = (char) (i+' ');
  14.             if (score[i] > 0)
  15.                 System.out.println(x + ": " + score[i]);
  16.         }
  17.     }
  18. }
  19.  
RAW Paste Data