Cari artikel di situs ini

Tanggapi komentar

coba-coba :D

public class sama{
    static String [ ] A = {"ani","andi","rudy","ifha","aan"};
    static String [ ] B = {"ani","rara","dona","ifha","lia"};
   
    public static void main (String[ ]args){
        for (int i=0;i<A.length;i++){
            for (int j=0;j<B.length;j++){
                if(A[i].equals(B[j])){
                    System.out.println("A["+i+"]="+A[i]+" sama dengan B["+j+"]="+B[j]);
                    }
            }
        }
    }
}

 

  • .equals() = digunakan untuk membandingkan 2 string, sama ato gag
  • deklarasi Array qm yg bernilai String salah, untuk isi datanya, dikasih tanda petik contoh = {"1","2","3","4"}
  • kalo Array qm bernilai integer, buat membandingkan cukup pakek sama dengan dua kali contoh = if (A[i]==B[j]) dan untuk deklarasi array integer, gak usah pakek tanda petik contoh = {1,2,3,4}

 

 

 

Bee^^3

Balas

Isi bagian ini tidak akan ditampilkan untuk umum.
  • Tag HTML yang dibolehkan: <p> <br> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <span> <blockquote> <table> <caption> <tbody> <tr> <td> <h1> <h2> <h3> <h4> <h5> <h6> <address> <pre>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>, <c>, <cpp>, <java>. Beside the tag style "<foo>" it is also possible to use "[foo]".

Informasi lebih lanjut tentang opsi format tulisan

Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated.