how to add a comment indicating that the method will determine if a number is a prime number. In the next line add the method header for this method which will be called isPrime. This method returns the value of a type boolean and takes an argument of type int, the parameter will be named number. Add a left brace on next line. in the body of the method add a comment stating that 1 is not a valid prime number, on the next line add an if statement to test whether the value of the parameter number is equal to 1.

View Answers

October 22, 2010 at 10:58 AM

Hi Friend,

Try the following code:

import java.util.*; class CheckPrime{ static boolean isPrime(int number){ boolean isPrime = false; int i = (int) Math.ceil(Math.sqrt(number)); while (i > 1) { if((number != i) && (number % i == 0)) { isPrime = false; break; } else if (!isPrime) isPrime = true; --i; } return isPrime; } public static void main(String[] args){ int num = 5; if (isPrime(num)) { System.out.println("Number is Prime"); } else{ System.out.println("Number is not Prime"); } } }

Thanks

Ads

Related Tutorials/Questions & Answers:

prime numbers application how to add a comment indicating 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

Prime Numbers Create a complete Java program that allows the user to enter a positive integer n, and which then creates and populates an int array with the first n prime numbers. Your program should then display the contents

Advertisements

prime numbers Write a java program to find the prime numbers between n and m

finding the prime numbers Hi, I am a beginner to java and I have problem with the code in finding the prime numbers, can someone tell me about... number is prime or not, follow the link and it will provide you in depth knowledge

Prime Numbers Create a program that calculates the prime numbers from any inputted start and end range of values (e.g. 5 and 28) and print the prime... = 0; System.out.println("Prime Numbers are:" ); for (int i = 1; i <

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

Prime Numbers from range how to find prime numbers in a given range which are palindromes?? Hi Friend, Try the following code: import java.util.*; public class PrimeAndPalindrome { static final int MAXNUMBER

Finding all palindrome prime numbers How do i write a program to Find all palindrome prime numbers between two integers supplied as input (start and end points are excluded

Prime numbers in Java between 1 and 100 Hi, How to display prime numbers in java between 1 and 100? Thanks Hi, Prime numbers... which prints prime numbers between 1 and 100. Here is complete for printing prime

Pick Prime Numbers from the ArrayList Programmers mostly used ArrayList... and non prime numbers separately. Here is the code: import java.util....(array); System.out.println("Prime Numbers are: "); for (int i = 0; i <

Application for print pyramid of numbers What is the code for printing the numbers like 1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1

Find Numbers which are palindrome and prime In this section, you will learn how to find the numbers from 1 to 500 which are palindrome and prime. To compute...() of boolean type. Now the list contains all the numbers which are palindrome

Java find prime numbers without using break statement In this tutorial, you will learn how to find the prime numbers without using break statement. You all are aware of Prime Numbers, these are the numbers which are either divided

write an application that print out the even numbers between the range 100-200 write an application that print out the even numbers between... and determine the even numbers between them. class EvenNumbers { public static

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

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... the bytes. In this example of writing java program to get prime numbers, we

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

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... numbers in the list. The Iterator class iterates the ArrayList and check whether

prime number get one number and check the number prime or not using if statement Java Check 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

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

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

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

prime number to check wethere given number is prime or not? ... is Prime!"); } else{ System.out.println("Number is not prime!"); } } } Thanks

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

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...); System.out.println("Prime Numbers are: "); for(int i=0;i

prime nos Instead of using break statement in finding the prime nos ,is there any other way ?? if it is there pls tell that also import java.io.*; class FindPrimeWithoutBreak { public static void main(String