+ 1

Is this program alright?

What I have to do is to create a program that asks the user how many legs there are in a farm of only cows and chickens. Then I have to tell him all the possible combinations of cows and chicken there could be in the farm. For example, if the number is 6, there could be 1 cow and 1 chicken or 0 cows and 3 chickens. The number entered is always a multiple of 2

30th Nov 2017, 5:58 PM
MoroAstray
MoroAstray - avatar
1 Odpowiedź
0
import javax.swing.JOptionPane; public class Program { public static void main(String[] args) { int i, totalTemp, nbCows, nbChickens, nbLegs; do{ nbLegs = Integer.parseInt(JOptionPane.showInputDialog("total legs")); }while(!(nbLegs%2==0)); i=0; do{ totalTemp=nbLegs; nbCows = nbLegs/(4*i); totalTemp = nbLegs - nbVaches*4; nbChickens=totalTemp/2; System.out.println(nbCows + nbChickens); i++; }while(!(nbLegs==nbChickens*2)); } }
30th Nov 2017, 5:58 PM
MoroAstray
MoroAstray - avatar