IntelliJ IDEA の使い方

Ubuntu 23.10 にインストールして使ってみました。

## インストール

```bash
sudo snap install intellij-idea-community --classic
```

## 起動

```bash
intellij-idea-community
```

File -> New -> Project
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/d8f422f3-d60d-16a4-61ac-65118a2b3cb1.png)


Console Application にします。
JDK のバージョンは、21 にして下さい。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/24aceba7-c6a3-4583-ec0f-b496f728fcc8.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/3bd6243b-c1a4-c700-c6a8-6b0a32decbe9.png)

## プログラム

```kt:Main.kt
fun main(args: Array<String>) {
    println("Hello World!")

    // Try adding program arguments via Run/Debug configuration.
    // Learn more about running applications: https://www.jetbrains.com/help/idea/running-applications.html.
    println("Program arguments: ${args.joinToString()}")
}
```


## 実行
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/53471c0d-ca99-afc4-aeba-46caf17f7d43.png)

実行結果

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/678ce749-cde1-81ca-0dc1-525ebee3d456.png)

```text
Hello World!
Program arguments: 

Process finished with exit code 0
```

## プログラムを複雑にします。

```Main.kt
fun main(args: Array<String>) {
    println("*** start *** Nov/03/2023 ***")
    val ax : ArrayList<Double> = arrayListOf()

    var nn = 0
    val nmax = 50
    for (it in 1..nmax){
        for (jt in it..nmax){
            val itjt2 = it*it + jt * jt
            for (kt in jt..nmax){
                val kt2 = kt * kt
                if (itjt2 == kt2){
                    val ratio = it.toDouble() / jt.toDouble()
                    if (!ax.contains(ratio)){
                        val outstr = "" + nn + "\t" + it + "\t" + jt + "\t" + kt + "\t" + ratio
                        println(outstr)
                        ax.add(ratio)
                        nn += 1
                    }
                    }
                }
            }
        }

    println()
    println(ax)
    println("*** end ***")
}
```

実行結果
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/a91de4ca-06a5-a643-2411-2ae787492f69.png)

```text
/home/uchida/.jdks/openjdk-21.0.1/bin/java -javaagent:/snap/intellij-idea-community/464/lib/idea_rt.jar=34231:/snap/intellij-idea-community/464/bin -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath /home/uchida/IdeaProjects/nov0301/out/production/nov0301:/home/uchida/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.0/kotlin-stdlib-jdk8-1.9.0.jar:/home/uchida/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.9.0/kotlin-stdlib-1.9.0.jar:/home/uchida/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.9.0/kotlin-stdlib-common-1.9.0.jar:/home/uchida/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar:/home/uchida/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.0/kotlin-stdlib-jdk7-1.9.0.jar MainKt
*** start *** Nov/03/2023 ***
0	3	4	5	0.75
1	5	12	13	0.4166666666666667
2	7	24	25	0.2916666666666667
3	8	15	17	0.5333333333333333
4	9	40	41	0.225
5	12	35	37	0.34285714285714286
6	20	21	29	0.9523809523809523

[0.75, 0.4166666666666667, 0.2916666666666667, 0.5333333333333333, 0.225, 0.34285714285714286, 0.9523809523809523]
*** end ***

Process finished with exit code 0
```