Skip to content

Instantly share code, notes, and snippets.

@Yuiki
Created July 4, 2015 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuiki/a3dac11ad393e8312ca6 to your computer and use it in GitHub Desktop.
Save Yuiki/a3dac11ad393e8312ca6 to your computer and use it in GitHub Desktop.
等差数列の和を求める。
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