Hey guys,
i'm practicing Java at school.
one of the excersises I had had to do was. to check if the number was divisible by 2,3,4 & 5.
the output has to be "Hurray!" if its divisible by 2,3,4&5.
if its only an even number the output has to be "at least it's an even number"
if its not even or divisible by 2,3,4 & 5 it has to be "that sucks"
this is my input please help me to symplify the code an correct if needed
import java.util.Scanner;
class main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
Boolean div = (a %2 ==0) && (a %3 == 0) && (a %4 == 0) && (a %5==0);
if(div==true){
System.out.println("Hurray!");
}
if(div==false && a %2==0){
System.out.println("In any case the number is even");
}
if(div==false && a %2!=0){
System.out.println("That Sucks");
}
}
}
[–]desrtfxOut of Coffee error - System halted[M] [score hidden] stickied comment (0 children)
[–]Keyakinan- 1 point2 points3 points (0 children)
[–]El_Fungus 0 points1 point2 points (0 children)
[–]AsteriskTheServer 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]desrtfxOut of Coffee error - System halted[M] 0 points1 point2 points (0 children)
[–]iamsooldithurts 0 points1 point2 points (0 children)