import java.io.*;
public class Page117
{
public static void main(String[] args) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
char letter;
String sentence;
int counter = 0;
char response = 'o';
do
{
System.out.print("Type a sentence: ");
sentence = input.readLine();
System.out.print("Type a character to find: ");
letter = (char) input.read();
for(int x=0;x<sentence.length();x++)
{
if(letter==sentence.charAt(x))
{
counter++;
}
}
System.out.println("Number of times " + letter + " occured is: " + counter);
System.out.print("Continue? [y/n]: ");
response = (char) input.read();
}while(response != 'n');
}
}
About the program: The user will enter a sentence. The user will also input a character and count how many of that character occurs in the sentence.
I've come across a little problem. How do I make it so that after the process, it allows me to input my response. Because after I enter the character and tells me the number of occurrences, it either exits or won't allow me to input anything.
I've tried almost everything in my code. I don't use do-while loops that much so this is kind of difficult for me. I don't use booleans that much either.