W3Schools Tryit Editor
[
フレーム
]
Run ❯
Get your
own Java
server
Go to Spaces
Ctrl+Alt+P
public class Main { public static void main(String[] args) { int[] nums = {12, 5, 9, 21, 21, 7}; Integer first = null, second = null; for (int n : nums) { if (first == null || n> first) { second = first; first = n; } else if ((second == null || n> second) && n != first) { second = n; } } if (second != null) { System.out.println("Second largest: " + second); } else { System.out.println("No distinct second largest value."); } } }
Second largest: 12
AltStyle
によって変換されたページ
(->オリジナル)
/
アドレス:
モード:
デフォルト
音声ブラウザ
ルビ付き
配色反転
文字拡大
モバイル