I know that nesting if statements inside switch case statements isn't optimal, but at the moment that's how I'm approaching things unless it absolutely won't work.
I have an int num coming from an input file that chooses one of three clocks to perform an operation on, the operation being defined by a character, also from the input file
So for example,
G 2
Is supposed to yield something like
>>time 2 is 00:00:00
I have a switch statement that looks for the character, and then once it finds it there's if statements to check int num and call the appropriate method with the appropriate clock object as a parameter. So I have this code
switch(action){
//calls getTime() with appropriate clock
case 'G':
if(num == 1){
getTime(c1);
}
else if(num == 2){
getTime(c2);
}
else{
getTime(c3);
}
break;
//other commands
}
However, its always displaying the time for c3 no matter what. I have a System.out.println(num) just before the switch statement, so I've checked and I know that num is correct. I can post more of my code if need be...
Aucun commentaire:
Enregistrer un commentaire