0

Hello Everyone,=>> How can we reducing code in this Switch Case without writing duplication again and again

int grade = Integer.parseInt(model.getValueAt(i, 3).toString()); switch (grade) { case 1: cbxGrade.setSelectedIndex(0); break; case 2: cbxGrade.setSelectedIndex(1); break; case 3: cbxGrade.setSelectedIndex(2); break; case 4: cbxGrade.setSelectedIndex(3); break; case 5: cbxGrade.setSelectedIndex(4); break; case 6: cbxGrade.setSelectedIndex(5); break; case 7: cbxGrade.setSelectedIndex(6); break; case 8: cbxGrade.setSelectedIndex(7); break; case 9: cbxGrade.setSelectedIndex(8); break; case 10: cbxGrade.setSelectedIndex(9); break; case 11: cbxGrade.setSelectedIndex(10); break; case 12: cbxGrade.setSelectedIndex(11); break; }

20th May 2022, 3:31 PM
Samnang Choeurn
Samnang Choeurn - avatar
2 Respostas
+ 3
int grade = Integer.parseInt(model.getValueAt( i,3).toString() ); cbxGrade.setSelectedIndex(grade-1);
20th May 2022, 3:44 PM
Jayakrishna 🇮🇳
0
Please someone
20th May 2022, 3:31 PM
Samnang Choeurn
Samnang Choeurn - avatar