Java Minimum and Maximum values in Array

前端 未结 13 1012
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 06:32

My code does not give errors, however it is not displaying the minimum and maximum values. The code is:

Scanner input = new Scanner(System.in);

int array[]          


        
13条回答
  •  心在旅途
    2020-12-01 07:14

    your maximum, minimum method is right

    but you don't print int to console!

    and... maybe better location change (maximum, minimum) methods

    now (maximum, minimum) methods in the roop. it is need not.. just need one call

    i suggest change this code

        for (int i = 0 ; i < array.length; i++ ) {
           int next = input.nextInt();
           // sentineil that will stop loop when 999 is entered
           if (next == 999)
           break;
           array[i] = next;
    }
    System.out.println("max Value : " + getMaxValue(array));
    System.out.println("min Value : " + getMinValue(array));
    System.out.println("These are the numbers you have entered.");
    printArray(array);
    

提交回复
热议问题