Monday 6 June 2016

Chapter 3 Exercise 16, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY.

3.16 (Random point) Write a program that displays a random coordinate in a rectangle.
The rectangle is centered at (0, 0) with width 100 and height 200.


public class ProgrammingEx3_16 {
 
 public static void main(String[] args) {
  double x = Math.random() * 100-50;
  double y = Math.random() * 200-100;
   
  System.out.print(x + "," + y);
 }
 
}

3 comments :

  1. why you subtract 100-50 and 200-100?

    ReplyDelete
  2. I would like to know as well why 100-50 and 200-100

    ReplyDelete
  3. I would like to know as well why 100-50 and 200-100

    ReplyDelete