java program that takes a 3 digit number n and finds out
whether
the number 2^n + 1 is prime, or if it is not prime find out
its
factors.

Answer Posted / vipul

public List checkPrime(int N) {
boolean isPrime = true;
List<Integer> list = new ArrayList<Integer>();
int p = 7;
for (int i = 2; i < p; i++) {
if (p % i == 0) {
isPrime = false;
list.add(i);

} else
isPrime = true;
}
if (isPrime) {
list.add(p);
}
return list;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you initialize an Applet?

621


Can constructor be static or final?

651


Can you access the private method from outside the class?

508


What is the difference between Java and C++?

615


What is polymorphism and what are the types of it?

505






Is a class subclass of itself?

604


What are three ways in which a thread can enter the waiting state in java programming?

686


What is the role of garbage collector in java?

493


How do you convert an int to a string in java?

546


Is node a data type in java?

498


What is the difference between int and integer in java?

514


What is super keyword explain with example?

534


How many types of array are there?

550


Can we create a constructor in abstract class?

573


Why stringbuffer is faster than string?

541