Write a Java program that prompts the user for an integer and then printsout all the prime numbers up to that Integer?

 /*

Write a Java program that prompts the user for an integer and then 

printsout all the prime numbers up to that Integer?

*/

import java.util.Scanner; 

class Eighteen

{

    public static void main(String arg[])

    {

        int no,prime;  

        Scanner input = new Scanner(System.in);

        System.out.print("\n Enter Number here: ");

        no = input.nextInt();

         System.out.print("\n ");

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

        {    

            prime=0;

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

            {

                if(i%j==0)

                {

                   prime=1; 

                }

            }        

            if(prime==0)

            {

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

            }

        }

        System.out.print("\n ");

    }

}

More Information on our channel Programmer Community

please like , share and subscribe to get notifications of new videos....

To understand this program video will coming soon on our you tube channel





Comments

Popular posts from this blog

Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.

Write a Java program to convert seconds to hour, minute and seconds.

Write a Java program to print the ascii value of a given character.