Answer the question
In order to leave comments, you need to log in
Why doesn't while loop work in java?
Please help with cycle.
I just started to learn ...
I read, googled, I still don’t understand.
Says "java: not a statement"
public static void main(String[] args) {
int beerNum = 99;
String word = "бутылок";
while (beerNum > 0) {
if (beerNum == 1) {
word = "бутылка";
beerNum = beerNum - 1;
}
System.out.println(beerNum + " " + word + " пива на стене");
System.out.println(beerNum + " " + word + " пива.");
System.out.println("возьми одну");
System.out.println("пусти по кругу.");
else (beerNum < 1) {
System.out.println("Нет бутылок пива на стене.");
}
}
}
Answer the question
In order to leave comments, you need to log in
This construction is incorrect.
else (beerNum < 1)
Either else { ... }
Eitherelse if (условие) {...}
You have an infinite loop, the number of bottles will not decrease, since their decrease occurs only when it is equal to 1, although initially there are 99 of them. Plus, the above remarks are also true.
public class Main {
public static void main(String[] args) {
int beerNum = 99;
String word = "бутылок";
while (beerNum > 0) {
if (beerNum == 1) {
word = "бутылка";
}
System.out.println(beerNum + " " + word + " пива на стене");
System.out.println(beerNum + " " + word + " пива.");
System.out.println("возьми одну");
System.out.println("пусти по кругу.");
beerNum = beerNum - 1;
}
System.out.println("Нет бутылок пива на стене.");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question