Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class countLetters {
- public static void main(String[] args) {
- int aWord = 0;
- Scanner input = new Scanner(System.in);
- String word;
- char[] wordLetters;
- int offset; //array index
- /* prompt user for a word */
- System.out.print("Enter a word: ");
- word = input.nextLine();
- wordLetters = word.toCharArray();
- int [] wordCount;
- wordCount = new int[wordLetters.length];
- while (aWord <= wordCount[word.length()]) {
- wordCount[aWord]++;
- if (wordCount[aWord] == word.length()) {
- break;
- }
- System.out.println(word + ": " + wordCount[ word.length()]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement