-1
有人可以告訴我什麼是我的code.I只能使用bufferedreader和loops.sh有人可以幫我用我的循環代碼
有人可以告訴我什麼是我的code.I只能使用bufferedreader和loops.sh有人可以幫我用我的循環代碼
我不知道你想要做什麼你的代碼或甚至如何開始閱讀。但這裏有一個循環
Scanner scanner = new Scanner(System.in);
System.out.println("Enter intitial food supply: ");
int foodSupply = scanner.nextInt();
System.out.println("Enter intial amount of animal: ");
int foodIntake = scanner.nextInt();
System.out.println("Enter amount of food added per hour: ");
int foodAdded = scanner.nextInt();
int hours = 0;
while (foodIntake < foodSupply){
hours++;
foodIntake *= 2;
foodSupply += foodAdded;
}
System.out.println("It took " + hours + " hours for animals to outgrow food supply");
System.out.println("Animals when food supply reached: " + foodIntake);
System.out.println("Food Supply after last hour: " + foodSupply);
1)的System.out.println聲明
initial = end2;
initialfood = j;
您沒有將初始和initialfood後添加這兩條線段的建議。因此,初始始終是初始輸入,初始食物始終是初始食物輸入。
從代碼行:
end=initial;
end have the same value every time...
2)
2),而(I = j)的!我和j之間沒有關係。爲什麼有這樣的情況。將其更改爲
while(j>0)
╔══════════════╦════════════╦════════════╦═════════════╦═══════╗
║ Hour-Animals ║ start-Food ║ start-Food ║ End-Animals ║ End ║
╠══════════════╬════════════╬════════════╬═════════════╬═══════╣
║ 1 ║ 10 ║ 1000 ║ 4990 ║ 20 ║
║ 2 ║ 20 ║ 4990 ║ 8970 ║ 40 ║
║ 3 ║ 40 ║ 8970 ║ 12930 ║ 80 ║
║ 4 ║ 80 ║ 12930 ║ 16850 ║ 160 ║
║ 5 ║ 160 ║ 16850 ║ 20690 ║ 320 ║
║ 6 ║ 320 ║ 20690 ║ 24370 ║ 640 ║
║ 7 ║ 640 ║ 24370 ║ 27730 ║ 1280 ║
║ 8 ║ 1280 ║ 27730 ║ 30450 ║ 2560 ║
║ 9 ║ 2560 ║ 30450 ║ 31890 ║ 5120 ║
║ 10 ║ 5120 ║ 31890 ║ 30770 ║ 10240 ║
║ 11 ║ 10240 ║ 30770 ║ 24530 ║ 20480 ║
║ 12 ║ 20480 ║ 24530 ║ 8050 ║ 40960 ║
║ 13 ║ 40960 ║ 8050 ║ -28910 ║ 81920 ║
╚══════════════╩════════════╩════════════╩═════════════╩═══════╝