A prime number is a number that can be divisible by 1 and itself.

Example 1,3,7,11,13

funmain() {varisPrime =true //1println("Enter a Integer Number")//2valnumber =readLine()?.toInt()!!//3for(iin2untilnumber)//4 {if(number%i==0)//5 { isPrime =false//6} }if(isPrime)//7 {println("Entered Number $numberis Prime Number")//8 }else{println("Entered Number $numberis not Prime Number")//9 } }

- Declare and intilize the isPrime variable with default value true
- Instruct the user to enter an Integer number to check is is prime or not
- Convert a user-entered number to Integer and assigned to a variable number
- Execute the for loop from 2 and number-1 (Because of it our logic requirements number always divisible by 1 and itself)
- Inside for loop, we will check if the mode of a given number is 0
- We will change the value of isPrime false
- Check the value of isPrime variable
- Print Number is Prime on Command Prompt
- Print Number is not Prime on Command Prompt

Output

Enter an Integer Number

7

Entered Number 7 is Prime Number

Entered Number 9 is not Prime Number