Brainliest!!!!! 50 points....
Whoever answers all the questions above will be marked as the brainliest and will get 50 points..
Java series questions... Answer in java
Answers
Answer:
Hi friend, I have tried my best in figuring out the code for the questions and I got two questions :
Explanation:
For the third question :
import java.util.Scanner;
public class Sum_Series
{
public static void main(String[] args)
{
double sum = 0;
int n;
System.out.println("1/1! + 2/2! + 3/3! + ..N/N!");
Scanner s = new Scanner(System.in);
System.out.print("Enter the no. of terms in series:");
n = s.nextInt();
Sum_Series obj = new Sum_Series();
for(int i = 1; i <= n; i++)
{
sum = sum + (double)i / (obj.fact(i));
}
System.out.println("Sum of series:"+sum);
}
int fact(int x)
{
int mul = 1;
while(x > 0)
{
mul = mul * x;
x--;
}
return mul;
}
}
FOR SECOND QUESTION :
public class Fibonacci {
public static void main(String[] args) {
int n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
for (int i = 1; i <= n; ++i)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}
Answer:
Explanation:
For the third question :
import java.util.Scanner;
public class Sum_Series
{
public static void main(String[] args)
{
double sum = 0;
int n;
System.out.println("1/1! + 2/2! + 3/3! + ..N/N!");
Scanner s = new Scanner(System.in);
System.out.print("Enter the no. of terms in series:");
n = s.nextInt();
Sum_Series obj = new Sum_Series();
for(int i = 1; i <= n; i++)
{
sum = sum + (double)i / (obj.fact(i));
}
System.out.println("Sum of series:"+sum);
}
int fact(int x)
{
int mul = 1;
while(x > 0)
{
mul = mul * x;
x--;
}
return mul;
}
}
FOR SECOND QUESTION :
public class Fibonacci {
public static void main(String[] args) {
int n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
for (int i = 1; i <= n; ++i)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum;
}
}
}