69 816
Assignments Done
Successfully Done
In February 2019

Answer to Question #57819 in Java | JSP | JSF for Nithya

Question #57819
Write a program that asks the user to input the first two terms of the sequence and then prints out the 50th term.
Expert's answer
import java.util.Scanner;

class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double first = scanner.nextDouble();
double second = scanner.nextDouble();

//Series was not specified in the question, so I wrote solutions for two possible interpretations

{//If the series is a geometric progression
if(first == 0){
System.out.println("First term is supposed not to be 0");
double q = second/first;
double res = first * Math.pow(q, 49);

{//If the series is a arithmetic progression
double d = second-first;
double res = first + 49*d;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions