Answer the question
In order to leave comments, you need to log in
Where is the error in the simplest JAVA script?
Compiled ideone.com/gA6knT
Script
:
class HelloWorld {
public static void main(String[] args) {
// int x = 10;
for (int x = 1; x<11; x=x+1){
if(x==1){
String name = "бутылка";
}
if(x==2 | x==3 | x==4){
String name = "бутылки";
}
if(x > 4 & x < 21){
String name = "бутылок";
}
System.out.println("У нас есть " + x + name);
}
}
}
Answer the question
In order to leave comments, you need to log in
1. The problem is in the scope of the name variable. Take out String name = null; before the loop, and in the loop already define it (name = ....)
2. use for(x =1; x<11; x++)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question