私のプログラムに問題があります。
whileループで見られる鳥の数を保存し、プログラムが終了したときに最も鳥が見えるようにしたい。
if文に問題があります。
助けていただければ幸いです。あなたの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