So I started learning Java only a few days ago and I'm doing really well except for this one exercise that boggles my mind. So the exercise is to "Write a program which displays all numbers from 1 to 30 indivisible by 3". So this is easy:
class numbers {
public static void main (String args[]) {
for (int i = 0; i <=30; i++){
switch(i % 3){
case 0 :
break;
default :
System.out.println(i);
break;
}
}
}
}
Except one of the variants says "use break
after divisibility by 3 is detected. Now I'm not sure if hte break
used in the code above is correct, as it is a part of switch
. I was wondering if there was an other way to do it.