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.
1
Expert's answer
2016-02-16T03:05:41-0500
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");
return;
}
double q = second/first;
double res = first * Math.pow(q, 49);
System.out.println(res);
}


{//If the series is a arithmetic progression
double d = second-first;
double res = first + 49*d;
System.out.println(res);
}
}
}

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS