- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Includes
Certificate & Practice Material
Programs for practice
In the program below, we've introduced beginers to programming in java
Source Code: find whether given number is prime or not
# This program finds whether given number is prime or not public class PrimeOrNot { public static void main(String[] args) { int n, i, flag = 0; Scanner sc = new Scanner(System.in); System.out.print("Enter a positive integer: "); int n = sc.nextInt(); for(i=2; i<=n/2; ++i) { // condition for nonprime number if(n%i==0) { flag=1; break; } } if (flag==0) System.out.print(n+"is a prime number "); else System.out.print(n+"is not a prime number "); }Output
Enter a positive integer: 6 6 is not a prime number