사용자로부터 입력 문자를 받고 소문자를 대문자로 변환하거나 그 반대로 변환하는 프로그램을 만들려고합니다. 변환이 수행 될 때마다 변경 횟수가 증가하고 '.' 가 입력되면 프로그램은 입력을 요구하지 않습니다. 이것은 내가 지금까지 아래로 무엇을 가지고 :Java 대문자, 소문자 질문
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);
}
}
변환 및 카운터는, 모든 입력 한 후, 어떤 이유로 라인 잘 작동하지만 "입력 문자를 마침표를 입력 할 때까지 입력이 계속됩니다."반복 모든 입력 후에 여러 번. 이 문제에 대한 해결책은 무엇입니까? 어떤 실수를 했습니까?
:하며'동안 위'("입력 문자 마침표를 입력 할 때까지 입력이 계속됩니다.") '반복. – yate
user3580294 - 고마워요! 이걸 몰랐어! – user3529827
yate - yup, 나는이 방법으로 그것을 바 꾸었습니다. 그러나 그 라인이 여러 번 반복되는 이유에 대해서도 궁금했습니다. 고마워! – user3529827