Java Minimum and Maximum values in Array

前端 未结 13 1015
没有蜡笔的小新
没有蜡笔的小新 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:21

    //To Find Max and Min value in an array without sorting in java

    import java.util.Scanner;
    import java.util.*;
    public class MaxMin_WoutSort {
     public static void main(String args[])
       {
          int n,max=Integer.MIN_VALUE,min=Integer.MAX_VALUE;
          System.out.println("Enter the number of elements: ");
          Scanner sc = new Scanner(System.in);
    
          int[] arr = new int[sc.nextInt()]; //U can't say static or dynamic.
                                             //UnWrapping object sc to int value;sc.nextInt()
          System.out.println("Enter the elements: ");
          for(int i=0;imax)               //Maximum Condition
                max = arr[j];
              else if(arr[j]

提交回复
热议问题