asked on
Random r = new Random();
int first = r.nextInt(9) + 1;
int second = r.nextInt(9) + 1;
while (second < first){
second = r.nextInt(9);
}
//answer
sum = first - second;
You only tell what is the largest.
sum /*[sic]*/ = Math.max(first,second)>second?first-second:second-first;
int first = r.nextInt(9) + 1;
int second = r.nextInt(Math.max(first - 1, 1)) + 1;
My whole point all along has been that first should ALWAYS be <= second.
rather than just getting a positive answer from two unknown numbers, undisplayed numbers
second = (int)(Math.random()*10);
first = Math.max(Integer.rotateRight(second,255),0);
I've got no idea whether you are speaking from a child's point of view, the programmer, or someone else., as you mentioned the game was for a child, but you didn't seem to grasp that.
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
TRUSTED BY
ASKER