Created
July 4, 2015 22:54
-
-
Save Yuiki/a3dac11ad393e8312ca6 to your computer and use it in GitHub Desktop.
等差数列の和を求める。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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