Home Tutorialhelp Comment Prime Checker Java Coding

 
 

Comment

Cris
Prime Checker Java Coding,
March 10, 2008 at 4:58 AM

I have this Prime Checking Java coding problem:

A prime number ‘p’ is a positive integer (p>1) that can only be divided evenly by:
a) ‘p’ Itself (so the result of the division is: p/p = 1)
b) 1 (so the result of the division is p/1 = p)

The first few prime numbers are:

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31

Write a Class PrimeChecker that has checkPrime() method as follows:

public class PrimeChecker {

public static boolean checkPrime(int anyNumber){

// write your logic here
}

public static void main(String[] args) {
boolean found = false;
for (int p=-5; p<35;p++){
found = checkPrime(p);
if (found){
System.out.print(p + "\t");
}
}
}
}

Obviously, the method checkPrime will take in any integer and return true of false depending on whether integer is Prime or not.

As a tester for your code, the main method is sending a series of integers to the checkPrime method.

Here is the expected output:

2 3 5 7 11 13 17 19 23 29 31

Thanks.
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
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 - 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
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 - 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 

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 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 

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-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 Tips and Examples

Prime number program in java
Prime number program in java In this example you will learn how to write a program to generate and check  prime number  in java. As we know prime... a class with class name prime number, using switch case, in case first using two 

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 Tips and Examples

Find out the prime number
Find out the prime number       This lesson of Java programming language will teach you the coding to find out whether a given number is prime or not. Here we have used the 'for loop 

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... prime number. ADS4ThUnitADS Here is the code of the java Program to get prime 

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 Beginners

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

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 

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 to enter any number. If the number entered by the user is prime then we have 

Java Beginners

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

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

finding the prime numbers
number is prime or not, follow the link and it will provide you in depth knowledge about your problem. http://www.roseindia.net/java/beginners/Prime_number.shtml...finding the prime numbers  Hi, I am a beginner to java and I have 

Java Beginners

Finding all palindrome prime numbers - Java Beginners
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 

Java Beginners

java coding - Java Beginners
java coding  dear sir, i'm doing a java coding using with netbeans ide, so i'm trying to pass some text from one jframe to another jframe which is both are already opend on screen then how to do it? please send me 

Java Beginners

java coding - Java Beginners
java coding  how to create a window that contain a list of all files of specified directory 

Java Beginners

coding - Java Beginners
coding  i need to start coding but i don't know how to start it so plz help me  Hi Friend, Please visit the following link: http://www.roseindia.net/java/ Thanks 

Java Beginners

Java Coding - Java Beginners
Java Coding  Code a for loop that adds the integers that are multiples of 5 starting with 50 and ending with 5. Each time the sum is increased, print it on a line at the console. Be sure to declare and initialize any required 

Java Beginners

Java Coding - Java Beginners
Java Coding  What is the meaning of following statement in Java? Clasname objectname = another_object_name.method_name; The Example Code is Given Below public void sessionCreated(HttpSessionEvent sessionEvent 

Java Beginners

coding - Java Beginners
coding  i need start coding but don't have any idea to start plz help me 

Java Beginners

Java Coding - Java Beginners
Java Coding  How do I code the following: Code a while loop that calculates the sum of the integers that are multiples of 5 starting with 5... on Java visit to : http://www.roseindia.net/java/ Thanks 

Java Beginners

Java Coding - Java Beginners
Java Coding  Code a private static method named printMessage that accepts a String parameter that represents the message. The method should simply print the message followed by a blank line at the console. Write a statement 

Java Beginners

Java Coding - Java Beginners
Java Coding  Code nested for loops that calculate the area of a rectangle that can range in size from a length and width of 1 to a length and width of 10. Print the area for each width for a given length on a single line 

Java Beginners

Prime Numbers
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 

Java Beginners

Java Coding - Java Beginners
Java Coding  Two overloading methods that returns average using following headers A) public static int average(int[] array) B) public static double average(double[] array The program should prompt the user to enter 

Java Beginners

coding problem - Java Beginners
coding problem  hi friend! Im new to jasper reports.how can i start that coding inorder to generate reports.can u send some sample programs for reporting?im badly need some clearly mentioned example because im new to jasper 

Java Beginners

Java Coding - Java Beginners
Java Coding  How do I code the following: Code a switch statement that tests the value of an int variable named weightInt. This variable contains... other number, set shippingBase to 14.95.  Hi friend I hope it hepls u 

Java Beginners

Java Coding - Java Beginners
Java Coding  Write a program containing two functions, bubbleSort( ) and mergeSort( ). Each function should take an array of integers, sort the array.... This program will need to have a main function that prompts the user for the number 

Java Beginners

JAVA Coding - Java Beginners
JAVA Coding  Have to write a function that will write out from 1...","sixty","seventy","eighty","ninty"}; public String convert(int number){ int n=1; int word ; string=""; while ( number != 0 ){ switch ( n ){ case 1 : word 

Java Beginners

Java Coding - Java Beginners
Java Coding  How do I code the following: Code a private static method named getUPSShipping that accepts a double value named weight and an integer named zipCode and returns a double value. This method should set the value 

Java Beginners

JAVA Coding - Java Beginners
JAVA Coding  Have to write a function that will write out from 1...","sixty","seventy","eighty","ninty"}; public String convert(int number){ int n=1; int word ; string=""; while ( number != 0 ){ switch ( n ){ case 1 

Java Beginners

Java Coding - Java Beginners
Java Coding  How do I code the following? Code an if/else statement that tests the value of a string variable named shippingMethod to determine if it has a value of ?UPS,? ?FEDEX,? or another value. If the value is ?UPS,? call 

Java Beginners

Java Coding - Java Beginners
Java Coding  How do I do the following: Code an if/else statement that tests the value of a string variable named shippingMethod to determine if it has a value of ?UPS,? ?FEDEX,? or another value. If the value is ?UPS,? code 

Java Beginners

Coding - Java Beginners
Coding  How to do a coding to view employee name, salary and EPF. The EPF is calculated from the salary like 10% from their salary. and it also show... the technologies you create the application in Java/JSP/Servlet/JSF/Struts 

Java Beginners

coding related - Java Beginners
coding related  what is the purpose of using these line in a program? char units = args[1].charAt(0); units = Character.toUpperCase.../java/java-conversion 

Java Beginners

coding problem - Java Beginners
coding problem  i had a big doubt. public ArrayList readExpenseType() throws ClassNotFoundException, SQLException,Exception { DBConnection dbc = new DBConnection(); Connection con = dbc.getConnection(); ArrayList 

Java Beginners

coding problem - Java Beginners
coding problem  hi! i declared date as date datatype in oracle now i need to retrieve date from database to my java code.how can i please help me urgent   Hi Friend, We are providing you a code that will retrieve 

Java Beginners

coding problem - Java Beginners
coding problem  i used netbeans software to develop frame.now i need to add values to JList from ArrayList object  Hi Friend, Try the following code: import java.util.*; import javax.swing.*; public class 

Java Beginners

coding
coding  Write a java program to Create table - Employee containing empId String (20), empName String (50), DOB Date, deptId String(20). Primary key is empId. Foreign Key is deptId. Populate some records 

Java Beginners

Coding - Java Beginners
 

Java Beginners

Problem in coding - Java Beginners
should report the number of rolls that it makes before the dice come up snake eyes 

Java Beginners

about coding - Java Beginners
 

Java Beginners

coding - Java Beginners
 

Java Beginners

java - Java Beginners
java  write a program in java to print first 10 prime number?  ... static void main(String args[] ){ int prime = 2; int count = 0; while(count < 10) { int k=0; for(int i = 2; i < prime ; i++){ if (prime%i == 0){ k=1 

Java Beginners

Java while coding - Java Beginners
Java while coding  Java loop and function coding question? How can I write an application that accepts a person's weight and displays the number of calories the person needs in one day using the formula calories = bodyWeight 

Java Beginners

Java Coding Problem - Java Beginners
Java Coding Problem  Q.1 How to write a while loop that displays... InputStreamReader(System.in)); System.out.println("Enter Number:"); num...) { System.out.print(" " + i + " "); } } } } For more information on Java visit 

Java Beginners

Java-mysql coding - Java Beginners
Java-mysql coding  Dear Sir, Suppose I have Employee master file in Mysql table format & I want to update that file thru JavaSwing Input format... employee joins, his master details are putted in Java-Swing Form, how I can insert 

Java Beginners

java coding help plz ?
java coding help plz ?  Given two integers N and M (N ΓΆβ?°Β¤ M), output all the prime numbers between N and M inclusive, one per line. N and M...{ static boolean isPrime(long number) { boolean isPrime = false 

Java Beginners

coding problem in netbeans - Java Beginners
coding problem in netbeans  hi, i have just started programming in netbeans,i'm facing a problem in a java application i create a jframe class and jbutton and jtextfeild inside it now i have created another class c1 

Java-Tutorials

Java coding for beginners
very beginning. Tutorial Java coding for beginners will enable you to know about... source codes for outputting word in Java. Java coding for beginners example 1.... See the source codes below: Java coding for beginners example 2 import 

Java Beginners

Multi-Threading - Java Beginners
-sorter . prime-sorter will display the prime number if it is greater than the previously displayed number. You have to write a multithreaded Java program...Multi-Threading  Consider a producer process prime-generator produces 

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 

Java Beginners

j2me sms coding - Java Beginners
 

Java Beginners

Java Coding
Java Coding  Hello, Can u please tel me how to improve my coding techniques.I am feeling difficulty with coding but I am perfect with my theory part 

Java Beginners

java - Java Beginners
java  i want the program for // show if the given number is prime... = input.nextInt(); if (isPrime(num)) { System.out.println("Number is Prime"); } else{ System.out.println("Number is not Prime 

Java Beginners

Java Programming and Coding problem - Java Beginners
Java Programming and Coding problem  How write a program that helps the user count his change. The program should ask how many quarters the user has, then how many dimes, then how many nickels, then how many pennies 

Java Beginners

Java - Java Beginners
Java prime number program  How to show the prime number in Java? Can...; if (AePrimeExample.checkPrime(mersenne)) { System.out.print("Found Mersenne prime: "...://www.roseindia.net/java 

Java Beginners

need model coding in java - Java Beginners
need model coding in java  i want model a program for an algorithm in java which is it has some transactions T1=ABCE T2=CDE T3=DE T4=CDEG T5=BG T6=AE T7=BCG T8=C T9=A now compare T9=A and T6=AE 

Java Beginners

coding in java
coding in java  write a code to calculate the product of odd integers from 1-15   class ProductOfOddIntegers { public static void main(String[] args) { long product=1; for(int i=1;i<=15;i 

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 

Java Beginners

java coding
java coding  Hi sir, WRITE A PROGRAMME TO MAKE EMPLOYMENT MANAGMENT HAVING COLORS AND FRAME IN IT,???? CAN U SUGGEST ME HOW TO MAKE IT IN CORE JAVA 

Java Beginners

simple code - Java Beginners
simple code  to input a number and check wether it is prime...(bf.readLine()); System.out.println("Prime number: "); for (i=1; i < num; i... = Integer.parseInt(buff.readLine()); System.out.println("Prime number 

Java Beginners

java coding
java coding  sir i need code for how to send meg from one system to another system 

Java Beginners

java coding
java coding  i am using netbean to my project and it is Desktop Application.i want my textfield to accept only numbers or only alphabets .........plez plez plez do help me..........i am just beginner to java codes 

Java Beginners

java coding
java coding  i need to to a project in java and the title is file parsing. i need to read a file or if a particular file is given i have to count the no of vowels, pick out some terms, and to display the details about that file 

Development process Questions

java coding
java coding  Hai,I am having order table in mysql database.when user click download button the order table data shows in csv format.Its very urgent.please help me. Thanks in advance 

Java Beginners

java coding
java coding  using swing i want to give an exit button which on clicking ask a msg "JOptionPane" is select "yes" then it should exit or else not....plez help me...... JOptionPane.showConfirmDialog(null,"DO YOU REALLY WANT 

Java Beginners

JAVA coding
JAVA coding  using classes and arrays implement the following create classes, inheritance, object and execute methods. there are 5 students in a class, capture the surname, first name, age and sex. capture their marks of a given 

Java Beginners

java programs - Java Beginners
java programs  Actually i am searching for the source code ,algorithm and flow chart for prime number ...can u suggest me where can i find it??? ...(); String primeNo = ""; int counter = 0; System.out.println("Prime Numbers between 

JDBC Questions

java coding
java coding  plz correct this one ....i want to retrive data row from databse ...all its working but for combobox it not.......plz plz plz help me...... private void jButton4ActionPerformed(java.awt.event.ActionEvent evt 

JDBC Questions

java coding
java coding  can any one plez tell me how to retrive a row from access to each field of swing... i hav tried this but i am getting an SQL error "SQLExceptionOccurred[Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect 

Design concepts & design patterns Questions

java coding
java coding  (person, student,employee, faculty and staff are classes) design a class named person and its two subclasses named student and employee    class Person { public String name; public String address; public 

Java Beginners

java query
java query  why do we divide the number by 2 in for loop in the prime number program 

Java Interview Questions

PRIME AND EVEN AND ODD - Java Interview Questions
PRIME AND EVEN AND ODD  how to write prime numbers?i want source code... want source code?  Hi Friend, 1)Following code displays the prime... args[]){ String primeNo = ""; int j=0; System.out.println("Prime Numbers 

WebSevices Questions

Java coding - WebSevices
Java coding for web services  How to start Java Coding for web services 

Java Beginners

how to upload resume coding - Java Beginners
 

Java Beginners

java - Java Beginners
up to a specific limit? Q2- write a program in java to check a given number for Fibonacci term? Q3- write a program in java to generate prime number up...-conversion http://www.roseindia.net/java/beginners I hope this will help you 

Java Beginners

coding for chart
coding for chart  I want to convert a character into binary then convert it into its diagram in form of digital electrical signals.How can I do java coding for this diagram 

Java Beginners

Image using Java coding
Image using Java coding  Hai, Display image in pdf file using Java coding through Xsl file.. Please help me.. xsl file generate the pdf file 

Java Beginners

color coding in java
color coding in java  hii..can anyone please help with auto coloring code in java swings..??a particular text field should have a particular color for a particular event..plzz help 

Java Magazine Questions

j2me coding - Java Magazine
in sms using j2me. i have a problem in coding for sending and receiving sms .i have a coding for receiving sms but it not work because that program need sending... a coding for sending and receiving sms in j2me 

Java Beginners

How can i write a datagrid coding - Java Beginners
How can i write a datagrid coding  Hi, I want make a datagrid..plz send me datagrid coding using mysql database and jsp..plz tell me brief description about grid how can i connect datagrid with database. Thanks 

Java Beginners

single frame coding in java
single frame coding in java  sir, i am a beginner in java.i want to do a desktop application in java in which a single frame satisfies all needs.but i want changes in that frame only.how can i solve this?i think multiple frames 

Java Beginners

Javascript coding for link a website to another upon verify the form - Java Beginners
Javascript coding for link a website to another upon verify the form  Pls tell me javascript coding for " open a website when we click the verify button in the form? ( after verifying the form go to the desired website).  

Java Beginners

coding shape
coding shape  i need to write a simple java program. the system must be in an applet and allows a user to choose whether to draw shapes such as circles, rectangles or lines on the screen. also, user can add circles by choosing 

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

Plz give java coding for this
Plz give java coding for this   ****** * * * *********** * * * ******   Hello Friend; below is the code : public class Pattern { public static void main(String[] args) { int 

JavaMail Questions

need of java coding - JavaMail
need of java coding  Design a java interface for ADT stack. Develop it and implement the interface using link list. Provide necessary exception handling for that implementations. pls mail me this lab program..its urgent 

JSP Servlet Questions

java coding - JSP-Servlet
java coding  how to send mail in LAN without internet using java progamme  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Thanks 

Java Beginners

java coding for creating table in the console
java coding for creating table in the console  write a java program to create table 

Advertisements Advertisements
 

 

 

DMCA.com