java
Type two statements using nextInt() to print two random integers between 0 and 9. End with a newline. Ex:
5
7
Note: For this activity, using one statement may yield different output (due to the compiler calling nextInt() in a different order). Use two statements for this activity.
import java.util.Scanner;
import java.util.Random;
public class DiceRoll {
public static void main (String [] args) {
Random randGen = new Random();
int seedVal = 0;
randGen.setSeed(seedVal);
/* Your solution goes here */
return;
}
}

Respuesta :

Answer:

Here are the two statements which use nextInt() to print two random integers between 0 and 9:

System.out.println(randGen.nextInt(10));

System.out.println(randGen.nextInt(10));

Explanation:

Here is the complete program:

import java.util.Scanner;   //to accept input from user

import java.util.Random;   // use to generate random numbers

public class DiceRoll {  //class definition

public static void main (String [] args)  {//start of main function  

Random randGen = new Random();   // creates a Random class object randGen

int seedVal = 0;   //sets starting point for generating random numbers

randGen.setSeed(seedVal);   //sets the seed of random number generator

System.out.println(randGen.nextInt(10));  //generates and prints the first random integer between 0 and 9 (10 is the range from 0 to 9) using nextInt method, which is used to get next random integer value from the sequence of random number generator

System.out.println(randGen.nextInt(10));   //generates and prints the second random integer between 0 and 9 (10 is the range from 0 to 9) using nextInt method

return;    }  }

Another way to write this is to initialize two int variables:

int integer1;

int integer2;

Now use two print statements to print these random integers between 0 and 9 as:

System.out.println(integer1= randGen.nextInt(10));

System.out.println(integer1= randGen.nextInt(10));

Another way to write this is:

Set the value of integer1 to a random number from 0 to 9 and same for integer2

int  integer1 = randGen.nextInt(10);

int  integer2 = randGen.nextInt(10);  

Now use two print statements to print these random integers between 0 and 9 as:  

System.out.println(integer1);

System.out.println(integer2);

Ver imagen mahamnasir