Skip to content

Instantly share code, notes, and snippets.

@Yuiki Yuiki/Main.java
Created Jul 4, 2015

Embed
What would you like to do?
等差数列の和を求める。
public class Main {
private static class ArithmeticProgression {
private final int a, n, d;
ArithmeticProgression(int a, int n, int d) {
this.a = a;
this.n = n;
this.d = d;
}
private int calculateArithmeticSeries() {
return n / 2 * (2 * a + (n - 1) * d);
}
}
public static void main(String[] args) {
ArithmeticProgression am = new ArithmeticProgression(1, 100, 1);
int result = am.calculateArithmeticSeries();
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.