java fizzbuzz and prime numbers program

Solutions on MaxInterview for java fizzbuzz and prime numbers program by the best coders in the world

showing results for - "java fizzbuzz and prime numbers program"
Liam
15 Feb 2016
1  public static void main(String[] args) {
2        // FIZZ BUZZ
3         for (int num=1; num<=100; num++) {
4             
5             if(num%3 == 0 && num%5 == 0){
6                 System.out.println("FizzBuzz");
7                 
8             }else if(num%3 == 0){
9                 System.out.println("Fizz");
10                 
11             }else if(num%5 == 0){
12                 System.out.println("Buzz");
13                 
14             }else if(isPrime(num)== true){
15                 System.out.println(num + " is prime");
16             }else{
17                 System.out.println(num);
18             }
19         }
20    }
21       // Prime Number
22       public static boolean isPrime(int num){
23        if(num==1)
24            return false;
25        for(int i=2;i<num;i++){
26            if(num%i==0)
27                return false;
28        }
29        return true;
30    }