zondag 4 december 2011


Math.Random() gives you a random floating point number. If you place (int) before it then it rounds the number to a integer value. To get a number above one then you must multiply the Math.Random() times a value.


import java.awt.*;
import java.applet.*;

public class MathRandom extends Applet {

 public void init() {

 public void paint(Graphics g) {

  g.drawString("Math random example",50,40);
  g.drawString("(int)(Math.Random() * 100) = "+(int)(Math.random()*100), 50, 60 );


Geen opmerkingen:

Een reactie posten