I'm trying to create a program that receives input characters from the user and converts the lowercase characters to uppercase and vice versa. Every time a conversion is made, the number of changes increments and when '.' is inputted, the program stops asking for an input. This is what I have down so far:
import java.io.*;
class Example5
{
public static void main(String args[]) throws IOException
{
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader (inStream);
char input = '\0';
int counter = 0;
while(!(input == '.'))
{
System.out.print("Input a character. Input will continue until you enter a period : ");
input = (char)stdin.read();
if((int)input > 96 & (int)input < 123)
{
char upperInput = Character.toUpperCase(input);
System.out.println(upperInput);
counter++;
}
else if((int)input > 64 & (int)input < 91)
{
char lowerInput = Character.toLowerCase(input);
System.out.println(lowerInput);
counter++;
}
}
System.out.println("The number of changes are : " + counter);
}
}
The conversion and the counter works fine but for some reason, after every input, the line "Input a character. Input will continue until you enter a period : " repeats multiple times after every input. Any solution to this problem? What mistake did I make?
Thanks in advance :)