5-10 Prime_Display

Post date: Apr 7, 2014 2:11:08 PM

package prime_display;

import java.util.Scanner;

public class Prime_Display 

{

        public static void main(String[] args) 

        {

            Scanner input=new Scanner(System.in);

            

            System.out.print("Please choose  one of them 1 , 2 : ");

            int number=input.nextInt();

            

            switch(number)

            {

                case 1:Display1(); break;

                case 2:Display2(); break;

                default: System.out.println("invalid number");

            }

        }

        public static void Display1() 

        {

            for (int i = 2; i <=100; i++) 

            {

                boolean flag=true;

                for (int j = 2; j <i; j++) 

                    if(i%j==0)

                        flag=false;

                if(flag&&i%10>=5)

                    System.out.print(i+" ");

            }

            System.out.println();

        }

        public static void Display2() 

        {

            for (int i = 2; i <=100; i++) 

            {

                boolean flag=true;

                for (int j = 2; j <i; j++) 

                    if(i%j==0)

                        flag=false;

                if(flag&&i%10<5)

                    System.out.print(i+" ");

            }

            System.out.println();

        }

   

}