OF JAVA
Q1- Using switch statement, write a menu driven program for the following: (i) To find and display the sum of the series given below: S = a- a 3 /5 + a5 /9 - a 7 /13 ……………………. to n (where a = 2)
(ii) To display the following series: 1 , 11 , 111 , 1111 , 11111 For an incorrect option, an appropriate error message should be displayed.
PLEASE GIVE THE ANSWER
Answers
Answered by
0
The sum of the series is:
S = a- a 3 /5 + a5 /9 - a 7 /13 …………………….to n.
Where the value of a=2.
The output should be 1,11,111,1111,11111.
Explanation:
import java.util.Scanner;
public class abc
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number : ");
int n = sc.nextInt();
int s = 0, c;
for (c = 1; c <= n; c++)
{
s = s * 10 + 1;
System.out.print(s + " ");
}
}
}
Similar questions
Math,
21 hours ago
English,
21 hours ago
Math,
1 day ago
Math,
8 months ago
Social Sciences,
8 months ago