僕はこれまで「Ruby on Rails」をメインに勉強してきましたが、現在は「Java」も勉強しています。
ということで僕が過去に「Ruby」で解いた問題を「Java」で解くとどうなるかを試してみました。
1⁴ + 2⁴ + 3⁴ + ........ + 40⁴
上記の計算の結果をプログラムで出していきます。
package example;
public class JavaGouse {
public static void main(String[] args) {
int count = 1;
int sum = 0;
while (count <= 40) {
sum += Math.pow(count, 4);
count += 1;
}
System.out.println(sum);
}
}
これで求めたい値である「21781332」を出すことができました。ただしまだ「Ruby」も「Java」も理解が不十分であるため、問題もあると考えられます。ご意見いただけるとありがたいです。