Write a program that asks the user to input the first two terms of the sequence and then prints out the 50th term.
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!
Learn more about our help with Assignments:
JavaJSPJSF