how to create a random number in java
import java.util.Random;
Random rand = new Random();
// Obtain a number between [0 - 49].
int n = rand.nextInt(50);
// Add 1 to the result to get a number from the required range
// (i.e., [1 - 50]).
n += 1;public class GuessTheNumber {
public static void main(String[] args) {
int randomInt = (int)(20.0 * Math.random());
int num1 = randomInt;
int num2 = 10;
if(num1 == num2){
System.out.println("Correct!");
} else if(num1 > num2){
System.out.println("Too low!");
} else{
System.out.println("Too high!");
}
}
}import java.util.Random;
class scratch{
public static void main(String[] args) {
Random rand = new Random();
System.out.println( rand.nextInt(5) );
//prints a random Int between 0 - 4 (including 0 & 4);
}
}
Also in Java:
- properties java 8 maven in pom xml
- java get input
- create instance object java
- The specified child already has a parent. You must call removeView() on the child's parent first
- java gateway process exited before sending its port number pyspark anaconda
- getordefault java
- import
- how to print to the console in java
- java shortest if else statement
- java how to get current date
- hashmap get value java
- set top corner of shape radius programmatically android
- how to create a random number in java
- gson parse json
- funzione random in java
- how to iterate hashmap java
- how to extract data from delimited text file in java
- how to format a datetime object to show date and time and milliseconds in java
- java
- creating random color in java
- replaceall in java
- java display message
- android studio remove notification bar
- how to make an arraylist java