Hi I am wondering if there's a way to make the following less redundant. Where 'ones', 'twos', 'threes', etc. are instance variables. (The switch statement doesn't allow them to be case arguments).
private int methodX(){
int consec=0;
if(ones==1){
consec++;
}
if(twos==1){
consec++;
}
if(threes==1){
consec++;
}
if(fours==1){
consec++;
}
if(fives==1){
consec++;
}
if(sixes==1){
consec++;
}
if(consec>=4){
return 30;
}
else {
return 0;
}
}
private int ones;
private int twos;
private int threes;
private int fours;
private int fives;
private int sixes;
Aucun commentaire:
Enregistrer un commentaire