Advertisement
Guest User

Untitled

a guest
May 26th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.     public class countLetters {
  4.  
  5.         public static void main(String[] args) {
  6.                
  7.                     int aWord = 0;
  8.                      Scanner input = new Scanner(System.in);
  9.                      String word;
  10.                      char[] wordLetters;
  11.                      int offset; //array index
  12.                      /* prompt user for a word */
  13.                 System.out.print("Enter a word: ");
  14.                  word = input.nextLine();
  15.                
  16.                  wordLetters = word.toCharArray();
  17.                  int [] wordCount;
  18.                         wordCount = new int[wordLetters.length];
  19.                      
  20.                      while (aWord <= wordCount[word.length()]) {
  21.                          wordCount[aWord]++;
  22.                           if (wordCount[aWord] == word.length()) {
  23.                               break;
  24.                              
  25.                              
  26.                           }
  27.                              System.out.println(word + ": " + wordCount[ word.length()]);
  28.         }
  29.     }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement