Home Discussion Discuss: Find out the prime number

• ### how (i==num) Dissanayake June 1, 2011 at 11:38 AM

I am a beginner to java and I have problem with this code, how the (i == num) thats my problem. because i's value getting after the loop i<num. hows it's equle to num. please send me the reply

• ### how is working this loopfaisal June 24, 2011 at 11:01 AM

i have this error from this program, Exception in thread "main" java.lang.NoClassDefFoundError: Prime_number/java

• ### ThanksRinku Rajole August 13, 2011 at 7:03 PM

i will try this program lots of time but it give error. Butnow my problem is solved so thanks.

• ### Another SolutionApurba August 17, 2011 at 3:07 PM

import java.util.Scanner; public class Prime_number { public static void main(String[] args) { Scanner k = new Scanner (System.in); int i=2; int a = k.nextInt(); while (i < a ) { int n = a%i; { if (n==0) { System.out.println("Not Prime"); break; } } i++; } if (i == a) { System.out.println("Prime number!"); } } }

• ### primejacinth1215 September 9, 2011 at 6:16 AM

what if i like to use "while"?

• ### Code inefficientAnonymous February 19, 2013 at 2:39 PM

This code is not efficient

• ### formula to find out prime numberDebasish Nanda October 10, 2011 at 3:59 PM

sir/medam please tell me the formula to find out the prime number

good code

• ### doubtnaga October 26, 2011 at 10:16 AM

in this check prime number program how "i" value becomes 11 ie if(i==num) { PRINT(is prime); }

• ### computer sciencekrishnakant November 15, 2011 at 5:02 PM

this very useful for bunkers

• ### ISC Computer Applications - Grade 11Nabil December 6, 2011 at 1:22 AM

In the last "if..." condition, the condition should be if (num - i == 1), as you are running the for loop from i = 2, to i < num.

• ### ThanksNadav David December 25, 2011 at 7:41 PM

It helped me a lot

• ### javaprajot January 17, 2012 at 7:40 PM

how the loops and break are used ??

• ### OptimisationBertie Wheen March 13, 2012 at 4:51 AM

instead of for (i=2; i < num ;i++ ) use for (i = 2; i < (int)Math.sqrt(num); i++)

• ### ProgramAnanimuz March 23, 2012 at 9:50 AM

Hey, just a question, but i could never equal the prime number because its a simple < symbol in the for loop right? if not please explain. is it because the ++ is added during the loop?

• ### prime no. programmesandeep kamboj April 2, 2012 at 11:48 AM

its very good explanation. thnks for good work

• ### want to learn from mistake rahul June 11, 2012 at 6:02 AM

why i can't use b's value out side the loop,where b is global. class a { public static void main(String arg[]) { int a=Integer.parseInt(arg[0]); int i,b; for (i=2;i<a;i++) { b= a%i; } if(b==0) { System.out.println( a +" is not prime"); } else { System.out.println(a+"Prime number!"); } } }

• ### Java program of prime numbersBobby k bose June 14, 2012 at 8:10 PM

Your java program of finding "prime numbers " did really helped me. Thanks for the program!

• ### this codeRaymond June 16, 2012 at 3:13 PM

Dude, this is a really speculative piece of code. The only thing it attempts to validate is the integer 11 as a prime number. It does that in both parts of your conditional statement, even though you used the string words "Not Prime"!! What about the other prime numbers that exist in the variable i, that is, 3, 5 and 7. That piece of code fails to capture them.

• ### upleaseshutupchetan August 20, 2012 at 10:42 AM

class abc { void display() { int a=11; int x; int c=0; for(x=1;x<=a;x++) { int d=(x%a==0); c++; } if(C==2) system.out.println("prime"); else system.out.println("not prime"); } }

• ### mathsmohammad September 16, 2012 at 7:59 PM

how can i the number is prime

• ### prime no.sipra January 6, 2014 at 11:59 PM

Thank u so much.I got my work done.

Subject (*):

Related Articles
Java Beginners

prime number
prime number  could u pls help me out in finding whether a number is a prime number or not?   import java.util.*; class CheckPrimeNumber... is Prime!"); } else{ System.out.println("Number

Java Tips and Examples

Find out the prime number
Find out the prime number      ... to find out whether a given number is prime or not. Here we have used the 'for loop' statement and given the required condition for a prime number. As we know

Development process Questions

prime number
prime number  check prime number using if statement   Java Check Prime Number

Development process Questions

prime number
prime number  check prime number using if statement   Java Check Prime Number

Java Beginners

prime number
prime number  To check a number entered by user is prime

Java Beginners

prime number
prime number  write a java program for prime number

Development process Questions

prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number

Java Beginners

prime number
prime number  HI!I want a java program that accepts a number from user and displays whether it is a prime number or not using BufferedReader

Java Beginners

prime number
prime number  To check a number entered by user is prime or not?   Java check prime number import java.util.*; class CheckPrimeNumber... is Prime!"); } else{ System.out.println("Number

Java Interview Questions

prime number
prime number  to check wethere given number is prime or not?  ... is Prime!"); } else{ System.out.println("Number... { static boolean isPrime(int number){ boolean isPrime=false; int

Java Beginners

finding the prime numbers
the problem. Thanks.   Want to know about how to find out the given number is prime or not, follow the link and it will provide you in depth knowledge...finding the prime numbers  Hi, I am a beginner to java and I have

Java Beginners

prime number - Java Beginners
prime number  this project is to determine if a phone number is a prime number. if the number is a prime number then print a message to the effect. if the number is not a prime number then print the prime factors of the number

Java Beginners

prime number - Java Beginners
prime number  i want to write a code in java that picks prime numbers... non prime numbers when prime numbers are finished   Hi Friend, Try... boolean isPrime(int number){ boolean isPrime=false; int i

Programming Tutorials

Find prime factors of non prime number
Find prime factors of non prime number In this section, you will learn how to find the prime factors of the non prime number. Here we have prompted the user... displayed a simple message and if the number is not a prime number we have find all

IDE Questions

prime palendrome
prime palendrome  Hi I want to write a program that ask a user to input a number, the program then list all the prime number that are palindrome below the number entered. Thks

IDE Questions

prime palindrome
prime palindrome  Hi I want to write a program in pascal that ask a user to input a number, the program then list all the prime number that are palindrome below the number entered. thks

IDE Questions

prime palindrome
prime palindrome  Hi I want to write a program that ask a user to input a number, the program then list all the prime numbers that are palindrome below the number entered. In pascal language Thanks

Java Beginners

prime number question - Java Beginners
prime number question  For the question located here: http... has to input the two numbers and it displays the prime numbers within the range...; System.out.println("Prime Numbers between "+num1+" and "+num2

Java-Tutorials

Prime Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any given number. Prime Number is a number that is not divisible by any number other... automatically prints Prime Number starting from 1 to 50. Example of Prime Number

Java Beginners

prime nos
prime nos  Instead of using break statement in finding the prime nos...[] args) { for (int number = 2; number <= 100; number++) { int maxFactor = (int)Math.sqrt(number); boolean isPrime = true; int

General

Prime Number in Java
Prime Number in Java       This Java programming tutorial will be read how to get prime number. First of all we will define a class "Prime Number". Java I/O package

Java Tips and Examples

Prime number program in java
Prime number program in java In this example you will learn how to write... a class with class name prime number, using switch case, in case first using two for loop generating prime number up to the limit number entered by user

Java Tips and Examples

Prime Number in Java
Prime Number in Java       This Java programming tutorial, we will be read how to get prime number.... If number is divided by any number that means it is not prime otherwise prime number

Java-Tutorials

Prime Number in Java
Prime Number in Java In this Java tutorial , you will learn how to write a Java program to get prime numbers between 1 to the desired number. To start..., if the number is divisible by any number, it means it is not prime otherwise

Java Beginners

Palindromic Prime Numbers
Palindromic Prime Numbers  Write a program that finds the first palindromic prime number above 100,000. Include the value of this prime in a comment at the start of the code

General

Prime And Fibonacci Number Finder
Prime And Fibonacci Number Finder In this section, you will learn how to find the prime numbers which are generated in the fibonacci series. To compute... number is prime or not? If it is prime Number, the number will get displayed

Java Beginners

prime numbers application
that the method will determine if a number is a prime number. In the next line add... a comment stating that 1 is not a valid prime number, on the next line add...)) { System.out.println("Number is Prime

Java Beginners

prime pal - Java Beginners
prime pal  1) WAP to print all prime-palindrome number range between 1-500 2) WAP to print all prime-Fibonacci number range between 1-500   Hi Friend, 1)Prime and Palindrome: import java.util.

Java Beginners

Prime Numbers from range
Prime Numbers from range  how to find prime numbers in a given range...=200; private int number; private ArrayList<Integer> list = new ArrayList<Integer>(); public PrimeAndPalindrome(int maxNum){ number=maxNum

Programming Tutorials

Pick Prime Numbers from the ArrayList
integer values in the arraylist and from the arraylist we have to find the prime and non prime numbers separately. Here is the code: import java.util....Pick Prime Numbers from the ArrayList Programmers mostly used ArrayList

Tutorial Topics
Questions by Category