Here the code for get three digit value 'n' and calculate r=2^n+1 then find that value 'r' is a prie or not, here i like store the integer value 'r' without exponential function and big Integer, please make a great help to me.
thanks in advance..

import java.*;
import java.math.*;

public class primenumber extends power{

public static void main(String a[])throws IOException {
//get input
power ob=new power();
DataInputStream dis=new DataInputStream(;
System.out.println(" Enter three digit number n:");
String nu=dis.readLine();
int n=Integer.parseInt(nu);
long nvalue=ob.powerr(n);

//find prime
long r;
int primevalue=0,i,j=0;
long factors[]=new long[100];

//System.out.println("not prime");
}//inner if
}//outer if
}//for ends
System.out.println("Given number is"+n+"");
System.out.println("Prime calculation for"+nvalue+"");
System.out.println("power value is"+nvalue+"");

System.out.println("The number "+nvalue+" is prime");
System.out.println("The number "+nvalue+" is not a prime");
for(int k=0;k<=j-1;k++)
System.out.print("," +factors[k]);

}//main end here
}//class end here

class power {
//find power
final int two=2;
long powvalue=1 , i;
long powerr(int x){
int n=x;
return powvalue;

Recommended Answers

All 6 Replies

I'm a bit confused here.
don't really see a question in your post, what is it you're having trouble with?

please try this with the three digit input ..

try what? what are you stuck with? what is it supposed to do and what is it (not) doing?

could you be a bit more specific about these things?

Sample output:1
Enter three digit number n:
Given number is13
Prime calculation for16384
power value is16384
The number 16384 is not a prime
BUILD SUCCESSFUL (total time: 9 seconds)

Sample output:2
Enter three digit number n:
Given number is26
Prime calculation for134217728
power value is134217728
The number 134217728 is not a prime
BUILD SUCCESSFUL (total time: 9 seconds)

if you give 31 (or) any big value as a input, system could not give output.Because prime calculation number "nvalue" will be a very big integer.

i gave 31 as an input and i got bug form system, please go through ..
Sample output:3
Enter three digit number n:
Exception in thread "main" java.lang.ArithmeticException: / by zero
at primenumber.main(
Java Result: 1
BUILD SUCCESSFUL (total time: 4 minutes 2 seconds)

if you are asked: enter a three-digit number, why do you only test with two-digit numbers? that Exception says that on line 40 of the code in your main class, you are dividing something by zero, which causes your exception

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.