public class HelloWorld{
public static void main(String []args){
for (int i=1; i<=10; i){
System.out.println((i*5)&&(i%3!=0));
}
}
}
What is wrong with line 5?
CodePudding user response:
The && is for combining two logical values (boolean-values: true/false-values). It sadly cannot combine with numbers (at least in java)
In your provided code the (i*5) results in a number, the (i%3!=0) in a boolean value. Java doesn't know how to combine those with &&, that's why you get an error.
A way to solve the error and get the code to work as intended is as follows:
public class HelloWorld{
public static void main(String[] args){
for(int i=1;i<=10;i ){
if(i % 3 != 0){
System.out.println(i * 5);
}
}
}
}
You have to use an if-statment to check for multiples of 3, the &&-operator is reserved to only combine boolean values.
CodePudding user response:
&& is a logical operator and therefore you are getting this error.
As per your requirement, you can add an if condition before System.out.println() to check if that multiple is not divisible by 3.
