## ICSE 2013 Computer Application Q9 Solution

Q. Using the switch statement, write a menu driven program:
(i) To check and display whether the number input by the user is a composite number or not (A number is said to be a composite, if it has one or more than one factors excluding 1 and the number itself).
Example: 4, 6, 8, 9 …
(ii) To find the smallest digit of an integer that is input:
Sample input: 6524
Sample output: Smallest digit is 2

ICSE 2013

Solution
import java.io.*;
/**
*
*/
{
public static void main(String args[])throws IOException
{
int n, count, ch, small, a, i;
System.out.println("Enter 1 for Composite number");
System.out.println("Enter 2 for Smallest digit search");
switch(ch)
{
case 1:                                           // for checking composite number
count=0;
System.out.print("Enter a number :");
for(i=2; i<=n/2; i++)
{
if(n % i == 0)
count++;
}
if(count>0)
System.out.println("Entered number is Composite number");
else
System.out.println("Entered number is Composite number");
break;
case 2:                                        // for checking smallest digit from a number
System.out.print("Enter a number :");
small=99;
while(n!=0)
{
a = n % 10;
if(a < small)
{
small = a;
}
n = n / 10;
}
System.out.println("Smallest number is " + small);
break;
default:
System.out.println("Wrong choice");
}
}

}

Output:
Enter 1 for Composite number
Enter 2 for Smallest digit search