I have a school project due next week and I'm trying to crack the way to solve this question. I need to develop a program (tester) for the code written below, which had to print the 2 smallest numbers out of 4 using if-switch. The numbers they want me to use are 0,1.
if (a > b) {
int tmp = b;
b = a;
a = tmp;
}
if (b > c) {
int tmp = c;
c = b;
b = tmp;
}
if (a > d) {
int tmp = d;
d = a;
a = tmp;
}
if (b > d) {
int tmp = d;
d = b;
b = tmp;
}
My limitations are:
Must only use: int, for, while, if, Scanner (so no break, array, Boolean, etc.) No user input, must enter to test a, d = 0 c, b = 1. I know there are 16 options, if all are true, then print verified, in any case there must be written in the tester a code that prints 1 example if false. I'm trying to solve this with for statements, however I only got as far as just printing 1 + 2, 3 + 4, ... in: for (int i = 0; i <= 16; i++).
How do I check the numbers they want for the test for the code above (0,1) over and over in for loop? I would appreciate a hint on printing just 1 example for the false print
Aucun commentaire:
Enregistrer un commentaire