Using the switch statement write a menu driven program.
3 To check and display whether a number input by the user is an even or odd no.
To find the smallest digit of an integer that is input :
Sample input
Sarmple gulpul Smallest digit is
2
For an incorrect choice, an appropriate error message should be displayed.
Answers
Answer:
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(); // input number
int choice=sc.nextInt(); // input choice
int temp=n;
int small=10;
switch(choice)
{
case 2: if(n%2==0)
{
System.out.println("Even number");
}
if(n%2!=0)
{
System.out.println("Odd number");
}
break;
case 3: while(temp>0)
{
int r=temp%10;
temp=temp/10;
if(r<small)
{
small=r;
}
}
System.out.println("Smallest digit of given number = "+small);
break;
default: System.out.println("Enter a valid choice");
break;
}
}
}
Explanation:
it is a java program