bhavna
jav beginners
1 Answer(s)      3 years and 4 months ago
Posted in : Java Beginners

pl. let me know the logic and the program to print the prime and twin prim numbers

thanks
View Answers

January 15, 2010 at 10:33 AM


Hi Friend,

Try the following code:

class TwinPrimes{

public static void main (String args[]){
String primeNo = "";
int j=0;
int LastPrime = 1;
System.out.println("Twin Primes are:" );
for (int i = 1; i < 100; i++){
for ( j = 2; j < i; j++){
if (i % j == 0) {
break;
}
}
if (i == j) {
primeNo += i + " ";
if ((i - LastPrime) == 2){
System.out.println("("+(i - 2)+","+i +")");
}
LastPrime =i;
}
}
System.out.println("Prime Numbers are: "+primeNo);
}
}

Thanks









Related Pages:
jav compolation error - Java Beginners
jav compolation error  find symbol error
jav beginners - Java Beginners
jav beginners  pl. let me know the logic and the program to print the prime and twin prim numbers thanks  Hi Friend, Try the following code: class TwinPrimes{ public static void main (String
jav
jav-util.zip
jav-util.zip  i need to load a zipfile in to my class while executing and i have extract each file in that zip and a particular file content i need to desplay how can i do this please help me
JAv method overloading
JAv method overloading  What restrictions are placed on method overloading
Jav Applets - Applet
Jav Applets  I need to write a small payroll program, using applet, that provides a text field for the number of hours, a text field for the pay rate, and a non-editable text field for the output. It should also also provide
jav a - Design concepts & design patterns
jav a  Q.1. Write a program in Java to perform the addition of two complex numbers.   Hi Friend, Try the following code: public class ComplexNumber{ private int a; private int b; public ComplexNumber
beginners questions
beginners questions  I need all the possible Java beginners questions to prepare for an Interview
java beginners - Java Beginners
the following links: http://www.roseindia.net/java/beginners/StringTokenizing.shtml http://www.roseindia.net/java/beginners/tokenizingjavasourcecode.shtml
programming - Java Beginners
programming for java beginners  How to start programming for java beginners
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
Struts 2 tutorial for beginners with examples
Struts 2 tutorial for beginners with examples  Where is the Struts 2 tutorial for beginners with examples on your website. Thanks   Hi, We have collection of many tutorials for beginners on our website. You can learn
Java for beginners - Java Beginners
://www.roseindia.net/java/beginners/index.shtml Thanks
Java - Java Beginners
Java  how to declare arrays   Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/array.shtml Thanks
array - Java Beginners
array  WAP to perform a merge sort operation.  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/arrayexamples/mergeSort.shtml Hope that it will be helpful for you. Thanks
Queue - Java Beginners
Queue  i'm working with queue on java. since im beginners im asking for additional example programs on queue using java to enhance my knowledge. thanks so much for the help! God bless
java - Java Beginners
java  ...can you give me a sample program of insertion sorting... with a comment,,on what is algorithm..   Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/arrayexamples
Program - Java Beginners
Program Java link list  I need program in Java to copy a file to another file  Hi Friend,For more informationhttp://www.roseindia.net/java/beginners/linked-list-demo.shtml
matrices - Java Beginners
matrices  Write a program to add the two matrices  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/MatrixSum.shtml Hope that it will be helpful for you. Thanks
basic java - Java Beginners
basic java  oops concept in java ?  Hi Friend, Please visit the following links: http://www.roseindia.net/java/beginners/oop-in-java.shtml http://www.roseindia.net/java/learn-java-in-a-day/oops.shtml Thanks
Learn PHP Tutorials for Beginners
Learn PHP Tutorials for Beginners  Hi, I am just pass-out from college and eager to learn the PHP. Can anyone suggest or provide me a resourceful information for php beginners. Thanks
php video tutorial for beginners with examples
php video tutorial for beginners with examples  php video tutorial for beginners with examples   PHP: Hypertext Preprocessor PHP is an open source server side scripting language. One can use PHP to create dynamic web
stringbuffer - Java Beginners
://www.roseindia.net/java/beginners/StringBuffer.shtml http://www.roseindia.net/java/beginners/ Thanks
programmes - Java Beginners
://www.roseindia.net/java/beginners/MatrixMultiply.shtml http://www.roseindia.net/java/beginners/MatrixSum.shtml http://www.roseindia.net/java/java-conversion/Dividing-of-two
help - Java Beginners
to : http://www.roseindia.net/java/beginners/what-is-java.shtml http://www.roseindia.net/java/beginners/where-java.shtml http://www.roseindia.net/java/beginners/ Thanks
java - Java Beginners
http://www.roseindia.net/java/beginners/DataConversion.shtml Thanks
java - Java Beginners
java  HOW AND WHERE SHOULD I USE A CONSTRUCTOR IN JAVA PROGRAMMING???   Hi Friend, Please visit the following links: http://www.roseindia.net/java/beginners/Construct.shtml http://www.roseindia.net/java/java
javaprograms - Java Beginners
://www.roseindia.net/java/beginners/array_list_demo.shtml Thanks
java - Java Beginners
java  hi!! i want 2 download jdk latest version so can u pls send me the link..?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/download_jdk.shtml Thanks
examples - Java Beginners
examples  as am new to java can you please help me with basic programs on java with their examples  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/index.shtml Hope
programming error - Java Beginners
/beginners/linked-list-demo.shtml Hope that the above links will be helpful for you
java downloads - Java Beginners
information. http://www.roseindia.net/java/beginners/download_jdk.shtml
program - Java Beginners
Java vector program  Please give me an example of Java vector program.Thanks!!  hi friendNow, read about vector program. Here, is the used without taking user input.http://www.roseindia.net/java/beginners
merge sorting in arrays - Java Beginners
merge sorting in arrays  Write a program to insert string or characters to an array and apply merge sorting on this array  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners
leap year logic - Java Beginners
leap year logic  hi frds.. can u give me logic for leap year..  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/Leapyear.shtml Thanks
java compilation error - Java Beginners
java compilation error  Hello madam/sir, i m a beginners in java. My problem is that i want to connect a login form to a frame containing 4 panels. how could i do it?Please help
Static method in java - Java Beginners
Static method in java  What are static method in Java  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/howtoaccessstaticmethod.shtml Hope that it will be helpful for you

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.