Quantcast
Channel: OKWAVE 閲覧数の多い質問(Java/253)【本日】
Viewing all articles
Browse latest Browse all 68675

配列から最大値・最小値

$
0
0
int[ ] ten = {10,20,30,40,50} 例えばこの初期化された配列の中から最大値と最小値を表示させるプログラムを作りたい場合はどのようにすればよいのでしょう? public class aaa {  public static void main(String[ ] args){   int[ ] ten = {10,20,30,40,50};   int 最大値 = ten[0];    for (int i = 0; i< ten.length;i++){ if (最大値 < ten[i]){ 最大値 = ten[i]; } } System.out.println("最大値は" + 最大値 + "です。"); } } これで最大値だけは表示させられるのですが、ここから最小値も表示させるにはどのように加えてけばいいか教えてください。お願い致します。

Viewing all articles
Browse latest Browse all 68675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>