Computer Science, asked by kittykatmeow, 5 months ago

Using a switch statement, write a menu driven programs to:
(a)Generate and display the first 10 terms of the Fibonacci series
0,1,1,2,3,5……
The first two Fibonacci numbers are 0 and 1, and each subsequent number is the previous two numbers.
(b)Find and display the sum of the digits of an integer.
Sample Input: 15390
Sample Input: Sum of the digits = 18
For an incorrect choice ,an appropriate error message should be displayed.

IF U BEG OR SPAM IM REPORTING

Answers

Answered by kamalrajatjoshi94
10

Answer:

See the answers in the attachments I made this program while practicing so i'm sending with output.

Hope it helps...

Mark as brainliest if the program is right.

Attachments:
Answered by sohelhowrah23
0

Answer:

import java.util.Scanner;

public class KboatFibonacciNDigitSum

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.println("1. Fibonacci Series");

System.out.println("2. Sum of digits");

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

int ch = in.nextInt();

switch (ch) {

case 1:

int a = 0, b = 1;

System.out.print(a + " " + b);

for (int i = 3; i <= 10; i++) {

int term = a + b;

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

a = b;

b = term;

}

break;

case 2:

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

int num = in.nextInt();

int sum = 0;

while (num != 0) {

sum += num % 10;

num /= 10;

}

System.out.println("Sum of Digits " + " = " + sum);

break;

default:

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

break;

}

}

}

Similar questions