Advertisement
Vengadora

02-censo-de-letras.java

Jul 31st, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class J02 {
  4.  
  5.   public static void main(String[] args) {
  6.     Scanner cin = new Scanner(System.in);
  7.     int[] alfabeto = new int[26]; //En java, los valores son 0 por defecto.
  8.  
  9.     String s = cin.nextLine();
  10.    
  11.     for(int i=0; i<s.length(); i++) {
  12.       char x = s.charAt(i);
  13.  
  14.       if('a' <= x && x <= 'z')
  15.     alfabeto[x-'a']++;
  16.  
  17.       if('A' <= x && x <= 'Z')
  18.     alfabeto[x-'A']++;
  19.     }
  20.  
  21.     for(int i=0; i<26; i++)
  22.       if(alfabeto[i] > 0)
  23.     System.out.println((char)('a'+i) + ": " + alfabeto[i]);
  24.    
  25.   }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement