I already posted the article about generating random numbers using PHP. This time, I converted it into Java language.
The following code will display random number between 1 to 50. Random function will return numbers from 0.0 to 0.999 so multiplying it with 50 and adding 1 to it will result to 1.0 and 50.95. But since you declare it as integer (int) then it will display 1 to 50.
Java Code
public class Random{Possible Output
public static void main(String[] args) {
int random = (int )(Math.random() * 50 + 1);
System.out.println(random);
}
}
1 / 5 / 50 / 45 / 15 / 25
0 comments:
Post a Comment