Java Menu driven program to find Composite number and Smallest digit search
import java.io.*;public class Menu
{
public static void main(String args[])throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(in);
int n, count, ch, small, a, i;
System.out.println("Enter 1 for Composite number");
System.out.println("Enter 2 for Smallest digit search");
System.out.print("Enter your choice :");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
count=0;
System.out.print("Enter a number :");
n= Integer.parseInt(br.readLine());
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:
System.out.print("Enter a number :");
n= Integer.parseInt(br.readLine());
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");
}
}
}
No comments:
Post a Comment