0

consider the following sample input / output. Input: java is Prime 29996224275833 Output: 29996224275833 is a prime number. In

please all code

7th Feb 2017, 2:20 AM
Avinash Jha
Avinash Jha - avatar
9 Réponses
+ 1
The rest should be easy if you've done the Java base module. public static boolean isPrime(long x){ for(long i = 2; i <= Math.sqrt(x); i++){ if(x%i == 0){ return false; } } return true; } Edit again: Woops, my mistake there, it's supposed to be x%i ...
7th Feb 2017, 3:47 AM
Robobrine
Robobrine - avatar
0
this code is not working for given input robobrine
7th Feb 2017, 3:04 AM
Avinash Jha
Avinash Jha - avatar
0
Have you used the corrected version? Had a little mistake at the if.
7th Feb 2017, 3:08 AM
Robobrine
Robobrine - avatar
0
when I am entering 29996224275833 I am getting InputMismatchexception
7th Feb 2017, 3:14 AM
Avinash Jha
Avinash Jha - avatar
0
it fine working for small input number but for that number given error
7th Feb 2017, 3:18 AM
Avinash Jha
Avinash Jha - avatar
0
Do you scan for longs?
7th Feb 2017, 3:20 AM
Robobrine
Robobrine - avatar
0
thanks
7th Feb 2017, 3:21 AM
Avinash Jha
Avinash Jha - avatar
- 1
Input: java isPrime 29996224275833 Output: 29996224275833 is a prime number. Input: java isPrime 29996224275834 Output: 29996
20th Feb 2017, 1:50 PM
Rajkishor Patel
Rajkishor Patel - avatar
- 1
please correct code give me
20th Feb 2017, 1:51 PM
Rajkishor Patel
Rajkishor Patel - avatar