using switch case write a menu driven program....
(I) to check and display whether the number input by the user is a composite number or not.
(ii) to find the smallest number of the integer that is input.
. sample input 6524
. smallest output: smallest digit is 2.
. for an incorrect choice an appropriate error message should be displayed....
pls answer it as fast u can....
hope u get the question...
HINT: both are the question of one program....
please solve it using switch statement...
Answers
Answer:
import java.util.*;
class SCase
{
Scanner sc=newScanner(System.in);
int res;
public void main( )
{
System.out.println("**Menu**");
System.out.println("Enter 1- To check if number is composite or not");
System.out.println("Enter 2- To find the smallest number");
System.out.println("Enter 0-To exit");
System.out.println("Enter your choice");
int ch=sc.nextInt( );
switch (ch)
{
case 1: Composite( ); break;
case 2: Smallest( ); break;
case 0: System.exit(0); break;
default: System.out.println("Wrong choice");
}
System.out.println("do you want to continue? Enter Y/N");
char ans=sc.next( ).charAt(0);
} //close do//
while (ans=='Y'||ans=='y');
} //close main method//
private void Composite( )
{
System.out.println("enter a number");
int n=sc.nextInt( );
{
if (fact (n)>1 && fact(n)!=n)
System.out.println(n+"is a composite number");
else
System.out.println(n+"is not a composite number");
}
private void Smallest( )
int m,o,p;
{
System.out.println("Enter an integer");
int n= sc.nextInt( );
{
for (i=0; i<10; i++)
{
while (o!=0)
{
p=o%10;
if (p==n)
{
System.out.println("The smallest number is:"+p);
}
System.out.println( );
}
}
}
}
}
Explanation: