Prime number program in java

Below all shared program are checked out with the 100% working.

Simple java program to find prime numbers. For prime no program in java, I have introduced you two java program to print prime numbers in a given range. This is a simple java program for starters  On the internet, I have seen many programmers design a harder program to check “prime or not program in Java” which use to create confusion for the starter. Must check Factorial program in java & Armstrong number in java.

 java program to print prime numbers in a given range

After seeing those program here am going to attract you below program for prime number in java. To make you simpler in understanding I have developed two different programs to find prime numbers in java. Get minimum and maximum sum.

Simple java program for prime number both part such as

In this simple java program to find prime numbers, I have used scanner class to take users input and also I have used prime number program in java using for loop. Suggested article Palindrome number in java.

  • To check prime or not program in java.            Download
  • java program to print prime numbers upto n.         Download

So now let’s see the prime number java program and also I have uploaded the .txt.file to download.

Prime or not program in java

Prime number program in java using scanner to check whether the number is prime or not. This is a simple java program. As before I have told you that here both are using the scanner class and for loop to make handier and user-friendly to the users. Check how to reverse number in java.

That as per the requirement users can give input to receive output for check prime number program in java. Take care of below java prime number program. Count repeated number.

1| import java.util.*;
2| public class factnum{
3| public static void main(String[] args){
4| Scanner input=new Scanner(System.in);
5| int num=input.nextInt();
6| checknum(num);
7| }
8| static void checknum(int x){
9| int temp=0;
10| for (int i=2; i<x-1; i++){
11| if(x%i==0){
12| temp=temp+1;
13| }
14| }
15| if(temp==0){
16| System.out.println(x+” is prime number “);
17| }else{
18| System.out.println(x+” is not prime number “);
19| }
20| }
21| }

Prime or not program in Java: Output

simple java program for prime number

Java program to print prime numbers upto n number

This simple java program for prime number also receive the help of a scanner and for loop to make handier. Using this below prime number program in java users are going to ask two input first one for starting number and second one till last number users require a prime number.

1| import java.util.*;
2| public class fact_num_series{
3| public static void main(String[] args){
4| Scanner input=new Scanner(System.in);
5| System.out.print(“Number begin from  x :: “);
6| int num=input.nextInt();
7| System.out.println();
8| System.out.print(“Till last number y :: “);
9| int num2=input.nextInt();
10| checknum(num, num2);
11| System.out.println();
12| }
13| static void checknum(int x, int y){
14| for (int j=x; j<y; j++){
15| int temp=0;
16| for ( int i=2; i<j-1; i++){
17| if(j%i==0){
18| temp=temp+1;
19| }
20| }
21| if(temp==0){
22| System.out.print(j+”  “);
23| }
24| }
25| System.out.println();
26| }
27| }

Java program to print prime numbers upto n number: Output

Program for prime number in java

Program for prime number in java users comment

As before I have discussed to introduce you two java program. This both java program for prime number taking care of by simple coating to check prime or not program in java.

After downloading the simple prime number program in java text file you make a change as per your need. In case of not making basic understanding this both above program for Java, you can comment me by a below-commenting box that I can try to help you resolve it.

Keep connected by Https://infosorce.com

Speak Your Mind

*

error: Content is protected !!
DMCA.com Protection Status