minimum value in java won't work

后端 未结 4 1727
予麋鹿
予麋鹿 2021-01-24 13:02

I need help because my brain cells cannot find what is wrong with this program! Here\'s the code

     import java.util.*;
      public class student{
      publ         


        
4条回答
  •  轮回少年
    2021-01-24 13:35

    You initialize you array. And then default values are given (every int is initialized 0)

       int []myArray= new int[num];
       int minValue=myArray[0];
    

    it will be 0

    so nothing smaller can be found than zero if you type in positive integers

    Solution First fill your array with the user input THEN do

     int minValue=myArray[0];
    

    Or use Integer.MIN_VALUE.

提交回复
热议问题