Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- public class RandomNumberGenerator
- {
- public static void main(String[] args)
- {
- int x = 0; //x is some number that I want to assign a value to
- /*
- * Math.random() returns a double value between 0 and 1.
- *
- * Here, I am looking for an integer value between 1 and 10.
- *
- * I will use Math.random() to find a value, and multiply by 10.
- *
- * Since this calculation will result in a double between 0 and 9, I will add 1.
- *
- * I will also cast my result to an int.
- */
- x = (int)(Math.random()*10+1);
- System.out.println(x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement