array_max.mj 673 Bytes
Newer Older
uwwrp's avatar
uwwrp committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class ArrayMax {
    public static void main(String[] args) {
        ArrayMax tmp = new ArrayMax();
        
        int a[] = new int[10];
        int i = 0;
        while(i < 10) {
            a[i] = System.in.read();
            i = i + 1;
        }

        System.out.write(tmp.max(a, 10));
        System.out.flush();
    }
    
    /*
      Calculates maximal value of array a
    */
    public int max(int[] a, int length) {
        if(length <= 0) return -1;
        int max = a[0];
        int i = 1;
        while(i < length) {
            if(a[i] > max) {
                max = a[i];
            }
            i = i + 1;
        }
        return max;
    }
}