All pastes #247430 Raw Edit

Anonymous

public text v1 · immutable
#247430 ·published 2006-11-13 14:36 UTC
rendered paste body
[vidarhol@hegg:~]$ cat a.java

class a {
    public static void main(String[] args) {
        int[] k=new int[] {4,2,4,5,1,7,6};

        int the_current_smallest=k[0];
        System.out.println("To begin with, the current smallest is the first, "+k[0]);
        for(int i=1; i<k.length; i++) {
            System.out.println("I am comparing the current smallest, "+the_current_smallest+" with "+k[i]);
            if(k[i] < the_current_smallest) {
                System.out.println(k[i]+ "is smaller, that is my new current smallest");
                the_current_smallest=k[i];
            } else {
                System.out.println(the_current_smallest+ "is still smallest, I keep it");
            }

        }
        System.out.println(the_current_smallest+"is the smallest item in the list");
    }
}
[vidarhol@hegg:~]$ javac a.java && java a
To begin with, the current smallest is the first, 4
I am comparing the current smallest, 4 with 2
2is smaller, that is my new current smallest
I am comparing the current smallest, 2 with 4
2is still smallest, I keep it
I am comparing the current smallest, 2 with 5
2is still smallest, I keep it
I am comparing the current smallest, 2 with 1
1is smaller, that is my new current smallest
I am comparing the current smallest, 1 with 7
1is still smallest, I keep it
I am comparing the current smallest, 1 with 6
1is still smallest, I keep it
1is the smallest item in the list
[vidarhol@hegg:~]$