What does “java result” means?

前端 未结 6 1745
悲&欢浪女
悲&欢浪女 2020-12-19 18:43

after execution of my program written in java I see this output:

java result: 2147483647

What does this number means anyway? T

6条回答
  •  天涯浪人
    2020-12-19 19:20

    You assign Integer.MAX_VALUE in five different places in your code; one of the locations is elements in the mins array.

    This code near the end of your main() method can print out values from the mins array:

       int result = 0;
       for(int i=0;iresult)
               result = mins[i];
    
       }
       if(result==Integer.MAX_VALUE){
           System.out.println("IMPOSSIBLE");
       }
       else{
           System.out.println(result);
       }
    }
        else{
            System.out.println("IMPOSSIBLE");
       }
    

    Here's a small test program to find out what Integer.MAX_VALUE actually is:

    $ cat test.java ; javac test.java ; java sars
    class sars {
        public static void main(String args[]) {
                System.out.println("Integer.MAX_VALUE: " + Integer.MAX_VALUE);
        }
    }
    Integer.MAX_VALUE: 2147483647
    

    I was wrong in my earlier comment about a -1 leaking through somewhere -- you've embedded the funny value five times into your code. :) I don't know which one is leaking out, or if your algorithm is actually working exactly as it should. Good luck hunting that down :) but at least with your full code posted, someone may help you find what we're both missing.

提交回复
热议问题