Hey,
I made this code with the bits and pieces of knowledge i have, but i don't know how to convert it into a while loop.
it is currently in a for loop.
the program counts how many certain letters there are in a sentence/ word.
String word;
String letter;
int index=0;
char singleLetter;
Scanner keys = new Scanner (System.in);
System.out.println("What is your word?");
word= keys.nextLine();
System.out.println("What is your letter?");
letter=keys.nextLine();
singleLetter = letter.charAt(0);
for( int i = 0; i < word.length(); i++ )
{
if( word.charAt(i) == singleLetter )
{
index++;
}
}
System.out.println( "The letter " + letter + " appeared " + index + " times in the word." );
}
}
any type of help would be appreciated.
thank you.