/** * Write a description of class StringClass here. * * @author (your name) * @version (a version number or a date) */ import java.util.*; public class StringClass { String input; public StringClass() { Scanner console = new Scanner(System.in); System.out.println("Give me your String:"); input = console.nextLine(); } public void findLetter(char letter) { int find = -1; int count=0; do{ find = input.indexOf(letter, find+1); if(find!=-1) count++; }while(find!=-1); System.out.println("\n****The letter " + letter + " was found " + count + " times.\n\n"); } /************* * This is an example I did in class on the board. It turns out this doesn't work * Fix it. Mess around with it and make it work. */ public void findLetter2(char letter) { int count = 0; int index = 0; while((index = input.indexOf(letter, index)) != 1) { count++; index++; } System.out.println(letter + " was found " + count + " and " + index); } public static void main(String [] args) { StringClass sc = new StringClass(); sc.findLetter('a'); sc.findLetter2('a'); } }