lundi 8 juillet 2019

how to comparing the strings between getSelectedItem of a java choice and values in a jtable column

How to comparing value from getSelectedItem of a java choice and value in a jtable with loop and if?

here's my code :

int baris = tbl_input_nilai.getRowCount();
String[] items = new String[baris];
String storeCom = inp_matkul.getSelectedItem();
int a=0;
int b=0;
for(int i=0;i<baris;i++){
    items[i] = (String) tbl_input_nilai.getValueAt(i, 2);
    if(storeCom.trim().equals(items[i].trim())){
        a=a+1;
      } else {
             b=b+1;
      }
  }
   if(a>b){
        System.out.print("Test");
   } else if(a<b){
       System.out.print("sd");
   }

it always going on else condition I wonder why, thank you.

Aucun commentaire:

Enregistrer un commentaire