0

How can i chek that the given number is prime or not.....plz suggest me a program

it must be written I simple codes...plz

22nd Feb 2018, 6:38 AM
Akshit Mittal
Akshit Mittal - avatar
1 Answer
+ 1
// Created by Andreas /* Author: Andreas Created: 24. FEB 2018 Description: The code checks if you entered a prime number or not ++++++++++++++++++++++++++++++++ ENTER A NUMBER FOR "X". WHEN YOU RUN THE PROGRAM IT WILL TELL YOU IF YOU ENTERED A PRIME OR NOT. ++++++++++++++++++++++++++++++++ */ public class Prime{ public static void main(String...arg){ int rest = 10; int x = 7; for(int i = 2;i < x/2+1 && rest != 0; i++) { rest = x % i; } if(rest == 0) { System.out.println("Its not a prime number"); System.out.println(rest); } else { System.out.println("Its a prime number"); System.out.println(rest); } } }
24th Feb 2018, 4:24 PM
Andreas Schenk
Andreas Schenk - avatar