Computer Science, asked by CarrieVictoria, 2 days ago

Using the switch statement, write a menu driven program to perform the following operations

If the users choice is 'D' or 'd' then accept a number, find and display the sum of the digits of the number multiplied by the count of number of digits in that number

Eg: if n=1234 then sum=1*4+2 4+3*4+4*4=40​

Answers

Answered by ashabisht1209
0

Answer:

import java.util.Scanner;

public class KboatMenu

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("1. Factors of number");

System.out.println("2. Factorial of number");

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

int choice = in.nextInt();

int num;

switch (choice) {

case 1:

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

num = in.nextInt();

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

if (num % i == 0) {

System.out.print(i + " ");

}

}

System.out.println();

break;

case 2:

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

num = in.nextInt();

int f = 1;

for (int i = 1; i <= num; i++)

f *= i;

System.out.println("Factorial = " + f);

break;

default:

System.out.println("Incorrect Choice");

break;

Similar questions