LoginSignup
0
0

More than 5 years have passed since last update.

要素数50の配列の中から、入力した整数以上の数と未満の数を出力するプログラム

Last updated at Posted at 2019-01-24

現在javaの勉強をしていて表題のプログラムを作成する課題をやっております。
まずランダムで要素数50の配列をつくり、その後入力された整数以上の数を出力、その後改行して入力された整数未満の数を出力したいのですが、うまくいきません。
どこを直したらよいかアドバイスいただけないでしょうか?

class test17 {
    public static void main(String[] args) {
        int[] array = PConsole.createRandomIntArray(1, 300, 50, true);
        int th= PConsole.inputIntNum(1, 300); // 閾値

        int upper = array[0];
        int lower = array[1];

        for (int i = 0; i < array.length; i++) {
            if ( array[i]>= th) {
              upper+= array[i]+" ";
            }else{
              lower+= array[i]+" ";
            }
        }
        System.out.println(th);
        System.out.println(upper);
        System.out.println(lower);
    }
}       
0
0
2

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