program to check whether the number is prime or not in java

Solutions on MaxInterview for program to check whether the number is prime or not in java by the best coders in the world

showing results for - "program to check whether the number is prime or not in java"
Lucas
18 Nov 2020
1public class Main 
2{
3public static void main(String[] args) 
4{
5int num = 100;
6boolean flag = false;
7for (int i = 2; i <= num / 2; ++i) 
8{
9if (num % i == 0) {
10flag = true;
11break;
12}
13}
14if (!flag)
15System.out.println(num + " is a prime number");
16else
17System.out.println(num + " is not a prime number");
18}
19}
Alina
21 May 2019
1#include <stdio.h>void main(){int value, rem;printf("Enter an int ");scanf("%d", &value);rem = value % 2;if (rem == 0)printf("%d is an even int\n", value);elseprintf("%d is an odd int\n", value);}