Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


bhavna
jav beginners
1 Answer(s)      5 years and a month ago
Posted in : Java Beginners


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

thanks

Advertisement
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 Tutorials/Questions & Answers:
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 compolation error - Java Beginners
jav compolation error  find symbol error
Advertisements
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
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
Beginners in Java
Beginners in Java  Hi, I am beginners in Java, can someone help me... tutorials for beginners in Java with example? Thanks.   Hi, want to be command over Java, you should go on the link and follow the various beginners
java beginners - Java Beginners
the following links: http://www.roseindia.net/java/beginners/StringTokenizing.shtml http://www.roseindia.net/java/beginners/tokenizingjavasourcecode.shtml
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
programming - Java Beginners
programming for java beginners  How to start programming for java beginners
Good tutorials for beginners in Java
Good tutorials for beginners in Java   Hi, I am beginners in Java... in details about good tutorials for beginners in Java with example? Thanks.   ... the various beginners tutorials related to Java http://www.roseindia.net/java/beginners
Java for beginners
Java for beginners  Java for beginners Which is the best resource... Java video tutorial for beginners. Thanks   Hi, Here are the best resources for Learning Java for beginners: Java Video tutorial Java tutorials
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
Tutorial For Java beginners
Tutorial For Java beginners  I am beginners in Java. Is there any good tutorial and example for beginners in Java? I want to learn Java before Jan... of December 2013. Check the Java Beginners Java Tutorial section for tutorials
Java programming for beginners video tutorials
Java programming for beginners video tutorials  Hi, I am trying to find the Java programming for beginners video tutorials. Let's know the url... video tutorial for beginners. This pages includes many video tutorials
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
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
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
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
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
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
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
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
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
stringbuffer - Java Beginners
://www.roseindia.net/java/beginners/StringBuffer.shtml http://www.roseindia.net/java/beginners/ Thanks
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
 

 

 

DMCA.com