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); } } }
Comments
Leave a comment