+ 9

Can anyone help me to implement this code using Java programming?

https://code.sololearn.com/cqJpM34ICi9H/?ref=app

15th Jan 2018, 6:42 PM
JULIUS FREDRICK
JULIUS FREDRICK - avatar
4 Answers
+ 25
all factors of a number will be <=num/2 //so u can run loop till int (num/2) only //do u want someone to re-write this in java ? import java.util.Scanner; public class GauravProgram{ public static void main(String[] args){ Scanner a=new Scanner(System.in); int x=a.nextInt(); //done @Saleh â˜ș boolean b=(x>1)?true:false; for (int i=2;i<=x;i++) { int c=x%i; if (c==0) b=false ; } if(b) System.out.println(x+" is prime number"); else System.out.println(x+" is not prime number"); } }
15th Jan 2018, 6:47 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 5
It will be more helpful @Gaurav
15th Jan 2018, 6:50 PM
JULIUS FREDRICK
JULIUS FREDRICK - avatar
+ 5
Thanks
17th Jan 2018, 8:43 AM
JULIUS FREDRICK
JULIUS FREDRICK - avatar
+ 3
import java.util.Scanner; class PrimeCheck { public static void main(String args[]) { int temp; boolean isPrime=true; Scanner scan= new Scanner(System.in); System.out.println("Enter any number:"); //capture the input in an integer int num=scan.nextInt(); scan.close(); for(int i=2;i<=num/2;i++) { temp=num%i; if(temp==0) { isPrime=false; break; } } //If isPrime is true then the number is prime else not if(isPrime) System.out.println(num + " is a Prime Number"); else System.out.println(num + " is not a Prime Number"); } }
18th Jan 2018, 12:00 AM
Tim Millar
Tim Millar - avatar