Quick actions

cmd+k|ctrl+k

Navigation

Languages

Mencari Terbesar

Snippet info

Language

Java

Visibility

public

Author

riyanto.droider

Created

2022-11-16T02:41:15.989525Z

Updated

2022-11-16T02:41:15.989525Z

class Main {
    public static void main(String[] args) {
        int a = 23;
        int b = 12;
        int c = 74;
        
        // cara 1:
        // if ((a > b) && (a > c))
        //     System.out.println("Terbesar: "+ a);
        // else if((b > a) && (b > c))
        //     System.out.println("Terbesar: "+ b);
        // else
        //     System.out.println("Terbesar: "+ c);
        
        
        // cara 2:
        // int terbesar = 0;
        
        // if (a > terbesar)
        //     terbesar = a;
        // if (b > terbesar)
        //     terbesar = b;
        // if (c > terbesar)
        //     terbesar = c;
            
        // System.out.println("Terbesar: "+ terbesar);
        
        
        // cara 3:
        // int terbesar = a;
        
        // if (b > terbesar) 
        //     terbesar = b;
        // if (c > terbesar)
        //     terbesar = c;
            
        // System.out.println("Terbesar: "+ terbesar);
        
        
        int[] angka = {23, 1245, 74, 12, 100, 25, 10, 1000, 56};
        int terbesar= 0;
        
        for(int i=0; i<angka.length; i++) {
            if (angka[i] > terbesar) 
                terbesar = angka[i];
        }
        System.out.println("Terbesar: "+ terbesar);
        
    }
}
INFO