Computer Science, asked by KrishnVasudev, 1 month ago

Using the switch statement, write a menu driven program :
(i) To check and display whether a 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 factor excluding 1 and the number itself).
Example : 4, 6, 8, 9
(ii) To find the smallest digit of an integer that is input.
Sample inputs: 6524
Sample output: Smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.​

Answers

Answered by rudrapratapsingh6227
5

Answer:

KnowledgeBoat Logo

Computer Applications

Using the switch statement, write a menu driven program:

To check and display whether a number input by the user is a composite number or not.

A number is said to be composite, if it has one or more than one factors excluding 1 and the number itself.

Example: 4, 6, 8, 9…

To find the smallest digit of an integer that is input:

Sample input: 6524

Sample output: Smallest digit is 2

For an incorrect choice, an appropriate error message should be displayed.

Java

Java Conditional Stmts

ICSE

31 Likes

ANSWER

import java.util.Scanner;

public class KboatNumber

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("Type 1 for Composite Number");

System.out.println("Type 2 for Smallest Digit");

System.out.print("Enter your choice: ");

int ch = in.nextInt();

switch (ch) {

case 1:

System.out.print("Enter Number: ");

int n = in.nextInt();

int c = 0;

for (int i = 1; i <= n; i++) {

if (n % i == 0)

c++;

}

if (c > 2)

System.out.println("Composite Number");

else

System.out.println("Not a Composite Number");

break;

case 2:

System.out.print("Enter Number: ");

int num = in.nextInt();

int s = 10;

while (num != 0) {

int d = num % 10;

if (d < s)

s = d;

num /= 10;

}

System.out.println("Smallest digit is " + s);

break;

default:

System.out.println("Wrong choice");

}

}

}

Answered by anishamewafarosh
1

Answer:

hope it's helps you

please mark me as brainliest

Attachments:
Similar questions