This is part of my initial code
int man;
int wives;
int sacks;
int cats;
int kits;
int objects;
//Assigning values
man = 1;
wives = man * 7;
sacks = wives * 7;
cats = sacks * 7;
kits = cats * 7;
objects = man + wives + sacks + cats + kits;
//calling variables,
System.out.println("");
System.out.println("The number of wives is: " + wives);
System.out.println("The number of sacks is equal to the number of wives (" + wives + "), multiplied by 7, which is:" + sacks);
System.out.println("The number of cats is equal to the number of sacks (" + sacks + "), multiplied by 7, which is:" + cats);
System.out.println("The number of kits is equal to the number of cats (" + cats + "), multiplied by 7, which is:" +kits);
System.out.println("The total number of living things met is equal to the man (" + man + "), added to the sum of wives (" + wives + "), sacks (" + sacks + "), cats ("+ cats + "), and kits (" + kits + "), which is:" + man + wives + sacks + cats + kits );
System.out.println("");
System.out.println("End Java Exection");
}
This equals 17493432401, which is incorrect
However, if I switch the last variable to this
System.out.println("The total number of living things met is equal to the man (" + man + "), added to the sum of wives (" + wives + "), sacks (" + sacks + "), cats ("+ cats + "), and kits (" + kits + "), which is:" + objects );
Then it gives the correct answer, 2801.
Why does the answer change, depending on whether I type it in the variable or in a string. I think it has something to do with exponential multiplication. My teacher explained that a string can't perform addition, but then my question would be why does an output occur?
The second part of my question is how could I add the objects so they add correctly within the string, or is it just not possible? Thank you for any help and long live teksyndicate!
P.S. : Apologies for terrible structure, I tried resetting the spacing but it simply won't allow me to do that, sorry.