Unleashed: Important Number Programs for ICSE Part-1
for other number programs click the link https://wordpress-343193-1101484.cloudwaysapps.com/duck-number
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
A deadly 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.
- 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
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Give a number");
int num=Integer.parseInt(br.readLine());
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
O/P: This is a primenumber
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
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Give a number");
int num=Integer.parseInt(br.readLine());
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
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter a number to check");
int num=Integer.parseInt(br.readLine());
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
http://www.youtube.com/user/trushnatej
Related Posts
Continue learning with these related articles

String Methods in Java for ICSE Class 10: 25 Output Questions with Answers
ICSE Class 10 Computer Applications practice on String class methods: length, charAt, indexOf, lastIndexOf, substring, replace, trim, compareTo, equals and more, with 25 board-style output questions and step-by-step answers.

Special Number Programs in Java for ICSE: Armstrong, Spy, Neon, Disarium, Pronic and More
Every special number asked in ICSE Computer Applications – prime, perfect, Armstrong, palindrome, automorphic, neon, spy, Niven, duck, buzz, Disarium, special and pronic numbers – with definitions, examples and one complete Java program that checks them all.

Math Library Methods in Java for ICSE Class 9 (with Outputs)
ICSE Class 9 Computer Applications notes on the Java Math class: sqrt, cbrt, pow, abs, max, min, ceil, floor, round, rint and random, with return types, tricky negative-number outputs and Java expressions for formulas.