0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Kotlin: プレイグラウンドの使い方

Last updated at Posted at 2023-10-18

Kotlin のプレイグラウンド

サンプルで入力したプログラム

pythagorean.kt
fun main() {
    println("*** start ***")
    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 ***")
}

実行結果

*** start ***
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 ***

image.png

参考

次のサイトでも、Web で Kotlin の実行が出来ます
paiza.io
https://play.kotlinlang.org/

0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?