Java Program to Display Prime Numbers

Java Program to Display Prime Numbers

print-prime-numbers-in-java
Today i will write two applications.One application will display prime numbers from 1 to 200 and the other application i will not specify the end number i.e from 1 to n.

1.Displaying Prime numbers from 1 to 200 in java

[
public class DisplayPrimeNumbers {
    public static void main(String args[])
    {
        int maximum=200;
        System.out.println("This application prints numbers between 1 and"+maximum);

        for(int j=1;j<=200;j++)
        {
            boolean ifPrime=true;

            for(int i=2;i<j;i++)
            {
                if(j%i==0)
                {
                    ifPrime=false;
                    break;

                }

            }

            if(ifPrime)
            {

                System.out.println(j +"  is a prime number");
            }
        }

    }

}
]

2.

1.Displaying Prime numbers from 1 to n in Java

[
import java.util.Scanner;

public class DisplayPrimeNumbers {

    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter N value");
        int maximum = input.nextInt();
        System.out.println("This application prints numbers between 1 and" + maximum);

        for (int j = 1; j <= maximum; j++) {
            boolean ifPrime = true;

            for (int i = 2; i < j; i++) {
                if (j % i == 0) {
                    ifPrime = false;
                    break;

                }

            }

            if (ifPrime) {

                System.out.println(j + "  is a prime number");
            }
        }

    }

}

]


COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: Java Program to Display Prime Numbers
Java Program to Display Prime Numbers
Java Program to Display Prime Numbers
https://3.bp.blogspot.com/-ZWSOiFw8H2w/WJRk0IHx5nI/AAAAAAAAGzE/6hWsFwI3yTQuiYaVbBs6CcBcPFn-XGSxwCLcB/s200/print-prime-numbers-in-java-min.PNG
https://3.bp.blogspot.com/-ZWSOiFw8H2w/WJRk0IHx5nI/AAAAAAAAGzE/6hWsFwI3yTQuiYaVbBs6CcBcPFn-XGSxwCLcB/s72-c/print-prime-numbers-in-java-min.PNG
Java Codes
http://www.download-all.net/2017/02/java-program-to-display-prime-numbers.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/02/java-program-to-display-prime-numbers.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy