Answers for "fizzbuzz and prime number in java"

1

java fizzbuzz and prime numbers program

public static void main(String[] args) {
        // FIZZ BUZZ
         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);
             }
         }
    }
       // Prime Number
       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;
    }
Posted by: Guest on January-28-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language