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




Have Programming Question? Ask it here!
 
 
 


bhavna
jav beginners
1 Answer(s)      4 years and 6 months 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
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
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
Java for beginners - Java Beginners
://www.roseindia.net/java/beginners/index.shtml Thanks
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 - 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
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
java downloads - Java Beginners
information. http://www.roseindia.net/java/beginners/download_jdk.shtml
javaprograms - Java Beginners
://www.roseindia.net/java/beginners/array_list_demo.shtml Thanks
programming error - Java Beginners
/beginners/linked-list-demo.shtml Hope that the above links will be helpful for you
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
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
java - Java Beginners
http://www.roseindia.net/java/beginners/DataConversion.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
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
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
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
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
jQuery tutorial for beginners
jQuery tutorial for beginners Learn jQuery with the help of our tutorial jQuery tutorial for absolute beginners. This is complete jQuery tutorial for beginners and is developed for the absolute beginners trying to learn jQuery
Best PHP tutorial for beginners
Best PHP tutorial for beginners  Hi Friends, I want to learn PHP programming language. Please let's know the best tutorials url for beginners. I... for beginners. Thanks
PHP Beginners Guide, Free PHP Beginners Guide
This PHP Beginners Guide will help and educate all the programmers especially the beginners who want to learn PHP as a prime subject or as a supplement... of Roseindia’s PHP Beginners Guide. This PHP Beginners Guide not only help
Java projects for beginners
In this tutorial you will be briefed about the Java projects for beginners... prepared for the especially beginners. You will have to create plenty... about the nature of your projects being beginners. You should also add
J2EE - Java Beginners
J2EE  I have just completed a beginners project using jsp and servlet on netbeans ide. I have adequate knowledge of core java. From where do i study the portion of JSP and Servlet in detail. What should i study after this.  
writing aprogram - Java Beginners
information, visit the following link: http://www.roseindia.net/java/beginners
explanation - Java Beginners
to know about the Garbage collection. http://www.roseindia.net/java/beginners
java - Java Beginners
); } } For more information on java visit to : http://www.roseindia.net/java/beginners
programs - Java Beginners
information.http://www.roseindia.net/java/beginners/arrayexamples/java_array_usage.shtmlamar.
Advertisements
 

 

 

DMCA.com