Menu
Question Index
...


Write a program to generate Arithmetic series given the first term, second term and the number of terms. Every term in the series is a fraction.

Input (Fraction, Fraction, Integer) Output (List)
{1 / 1}, {3 / 2}, 11 [{1 / 1}, {3 / 2}, {2 / 1}, {5 / 2}, {3 / 1}, {7 / 2}, {4 / 1}, {9 / 2}, {5 / 1}, {11 / 2}, {6 / 1}]
{1 / 2}, {2 / 3}, 8 [{1 / 2}, {2 / 3}, {5 / 6}, {1 / 1}, {7 / 6}, {4 / 3}, {3 / 2}, {5 / 3}]
{-1 / 2}, {-1 / 1}, 9 [{-1 / 2}, {-1 / 1}, {-3 / 2}, {-2 / 1}, {-5 / 2}, {-3 / 1}, {-7 / 2}, {-4 / 1}, {-9 / 2}]
{5 / 2}, {2 / 3}, 7 [{5 / 2}, {2 / 3}, {-7 / 6}, {-3 / 1}, {-29 / 6}, {-20 / 3}, {-17 / 2}]
{1 / 3}, {7 / 4}, 9 [{1 / 3}, {7 / 4}, {19 / 6}, {55 / 12}, {6 / 1}, {89 / 12}, {53 / 6}, {41 / 4}, {35 / 3}]

class GenerateArithmeticSeries

{    public static void main(String s[])
    {
        Fraction firstNumber = new Fraction(1, 3);
        Fraction secondNumber = new Fraction(7, 4);
        int noOfTerms = 10;
        System.out.println(generateArithmeticSeries(firstNumber, secondNumber, noOfTerms));

    }


public static List<Fraction> generateArithmeticSeries(Fraction firstNumber, Fraction secondNumber, int noOfTerms) {
//Write code here to generate the Arithmetic series up to the given number of terms.
}

//If required, write the additional methods here.
}
class Fraction {

int numerator;
int denominator;

public Fraction() {
}

public Fraction(int numerator, int denomenator) {
this.numerator = numerator;
denominator = denomenator;
}

@Override
public String toString() {
return "{" + numerator + " / " + denominator + "}";
}
}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App