내 프로그램에 문제가 있습니다.
while 루프에서 보이는 새의 수를 저장하고 프로그램 종료시 가장 많이 보이는 새를 인쇄하고 싶습니다.
if 문에 문제가 있습니다.
도움이 될 것입니다. 의Java While 루프 문제 (신규)
import java.util.*;
class gardenbird
{
public static void main(String[] main)
{
askbird();
System.exit(0);
}// END MAIN METHOD
public static void askbird()
{
final int sentinel = -1;
int mostseen = 0;
int howmany = 0;
print("When you want to end the program type in "+sentinel);
while(howmany != sentinel)
{ Scanner scanner = new Scanner(System.in);
print("Which bird have you seen?");
String bird = scanner.nextLine();
howmany = input("How many where in your garden at once?");
if(howmany>mostseen)
{
howmany = mostseen;
}
print("You saw " + howmany+ " " + bird +"\n It was the most common bird in your garden.");
}
}
public static String print(String message)
{
System.out.println(message);
return message;
}
public static int input(String count)
{
Scanner scanner = new Scanner(System.in);
print(count);
String number1=scanner.nextLine();
int number = Integer.parseInt(number1);
return number;
}
}
'howmany = mostseen'은'mostseen = howmany'이어야합니다. – JimmyB
새로운 Scanner 인스턴스를 과도하게 사용하는 것을 다시 생각해보십시오. – Fildor