java fizzbuzz and prime numbers program code example
Example: java fizzbuzz and prime numbers program
public static void main(String[] args) {
for (int num=1; num<=100; num++) {
if(num%3 == 0 && num%5 == 0){
System.out.println("FizzBuzz");
}else if(num%3 == 0){
System.out.println("Fizz");
}else if(num%5 == 0){
System.out.println("Buzz");
}else if(isPrime(num)== true){
System.out.println(num + " is prime");
}else{
System.out.println(num);
}
}
}
public static boolean isPrime(int num){
if(num==1)
return false;
for(int i=2;i<num;i++){
if(num%i==0)
return false;
}
return true;
}