0
0

More than 3 years have passed since last update.

【Java】4乗的ガウスを解く

Last updated at Posted at 2021-08-06

 僕はこれまで「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」も理解が不十分であるため、問題もあると考えられます。ご意見いただけるとありがたいです。

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0