Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
760 views

Prime Triplets (JAVA PROGRAM PDF)

JAVA PROGRAM TO FIND THE TRANSPOSE OF A MATRIX (A transpose of an array obtained by interchanging the elements of the rows and columns) . WITH COMMENTS AND DETAILS TO HELP YOU UNDERSTAND THEM.THIS PROGRAM HAS BEEN RUN ON BlueJ AND IS ERROR FREE.IT WILL SURELY HELP YOU IN STUDYING JAVA PROGRAMS FOR EXAMS OR OTHERWISE.

Uploaded by

AMRENDRA SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
760 views

Prime Triplets (JAVA PROGRAM PDF)

JAVA PROGRAM TO FIND THE TRANSPOSE OF A MATRIX (A transpose of an array obtained by interchanging the elements of the rows and columns) . WITH COMMENTS AND DETAILS TO HELP YOU UNDERSTAND THEM.THIS PROGRAM HAS BEEN RUN ON BlueJ AND IS ERROR FREE.IT WILL SURELY HELP YOU IN STUDYING JAVA PROGRAMS FOR EXAMS OR OTHERWISE.

Uploaded by

AMRENDRA SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Class Prime_Triplets

package
/**
*
*
*
*
*
*/

1/2

Practical_Questions.Sample_Questions;
QUESION
Program to generate PRIME TRIPLETS between two
given limits.
If no ne are found print appropriate error.

import java.io.*;
public class Prime_Triplets
{
int s;
int l;
int c;
DataInputStream d=new DataInputStream(System.in);
Prime_Triplets()
{
c=0;
s=0;
l=0;
}
boolean is_prime(int a,int n)
{
boolean j=true;
if(a==1)
{
j=false;
}
if(n<a)
{
if(a%n==0)
{
j=false;
}
if(a%n!=0)
{
j= is_prime(a,++n);
}
}
return j;
}
boolean generate_triplets(int x)
{
Jan 19, 2015 11:20:35 PM

Class Prime_Triplets (continued)

2/2

if(is_prime(x,2))
{
if(is_prime(x+2,2))
{
if(is_prime(x+6,2))
{
System.out.println(x+"\t"+"\t"+(x+2)+"\t"+(x+6));
c++;
return true;
}
}
if(is_prime(x+4,2))
{
if(is_prime(x+6,2))
{
c++;
System.out.println(x+"\t"+"\t"+(x+4)+"\t"+(x+6));
return true;
}
}
}
return false;
}
void main()throws IOException
{
Prime_Triplets obj=new Prime_Triplets();
System.out.println("ENTER LOWER LIMIT");
s=Integer.parseInt(d.readLine());
System.out.println("ENTER UPPER LIMIT");
l=Integer.parseInt(d.readLine());
System.out.println("PRIME TRIPLETS ARE");
for(int i=s;i<l+1;i++)
{
generate_triplets(i);
}
if(c==0)
{
System.out.println("NO TRIPLETS FOUND");
}
}
}

Jan 19, 2015 11:20:35 PM

prime_Tr1.main();
ENTER LOWER LIMIT
1
ENTER UPPER LIMIT
20
PRIME TRIPLETS ARE
5

11

11

13

11

13

17

13

17

19

17

19

23

prime_Tr1.main();
ENTER LOWER LIMIT
10
ENTER UPPER LIMIT
30
PRIME TRIPLETS ARE
11

13

17

13

17

19

17

19

23

You might also like