### Number programs are very important because every year at least one number program is asked in the ICSE computer application board exam.

for other number programs click the link
https://java4school.com/duck-number

Here are some programs for the ICSE computer application students. They are number programs. These programs are very important because they can be asked in the ICSE boards as it is or with a little twist or in combination with other programs.

1. Prime Number: A prime number is a number that is divisible only by two numbers one and itself(For example 5 , it is divisible only by 1 and itself)

import java.io.*;
class prime_number
{
public static void main()throws IOException
{
System.out.println(“Give a number”);
int count=0;
for(int i=1;i<=num;i++)
{
if(num%i==0)
count++;
}
if(count==2)
{
System.out.println(“This is a prime number”);
}
else
{
System.out.println(“This is not a prime number”);
}
}
}

I/P:- 5

I/P:- 12

O/P: This is not a prime number

2. Perfect Number: A perfect number is a number whose factor’s(excluding the number
)sum is equal to the number(for example 6 has three factors 1, 2 and 3 and their sum is 6)

import java.io.*;
class perfect_number
{
public static void main()throws IOException
{
System.out.println(“Give a number”);
int sum=0;
{
for(int i=1;i<num;i++)
{
if(num%i==0)
sum+=i;
}
if(sum==num)
{
System.out.println(“This is a perfect number”);
}
else
{
System.out.println(“This is not a perfect number”);
}
}
}
}

I/P:- 6

O/P: This is a perfectnumber

I/P:- 12

O/P: This is not a perfect number

3. Special number:A special number is a number whose digits factorial’s sum is equivalent to the number(For example 145:- 1|+4|+5|=1+24+120=145). In this program a special() function is made to do the task, the function is called from main function by making an object of the class.

import java. io. *;
class specialno
{
public void special(int num)
{
int n=num;int sum=0;
while(num!=0)
{
int pro=1;
int rem=num%10;
num=num/10;
for(int i=1;i<=rem;i++)
pro*=i;
sum+=pro;
}
if(sum==n)
System.out.println(“This is a special number”);
else
System.out.println(“This is not a special number”);
}

public static void main()throws IOException
{
System.out.println(“Please enter a number to check”);
specialno obj=new specialno();
obj.special(num);
}
}

I/P:- 145

O/P: This is a special number

I/P:- 12

O/P: This is not a special number

For videos related to java programming