Roll the Dice pt. 2

For one of my first assignments, I decided to write Java code to roll dice. See the original code here!

Highlighted changes:

Receive user input to continue rolling the dice using a while loop.

Created a end message

Here is an online java compiler with an example run.

Sample run with one response

Here is the code for the program to roll two die.

package com.company;
import java.util.Random;
import java.util.Scanner;

public class DS106 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Random numGenerator = new Random();
System.out.println("Would you like to roll the dice? respond: yes or no");
String response = in.nextLine();
while (response.equalsIgnoreCase("yes")) {
int number = numGenerator.nextInt(6) + 1;
if (number != 0) {
System.out.println("The first die is a " + number + ".");
}
int number2 = numGenerator.nextInt(6) + 1;
System.out.println("The second die is a " + number2 + ".");

int totalNumber = number + number2;
System.out.println("The total number from the dice is " + totalNumber + ".");
System.out.println();
System.out.println("Would you like to roll the dice?");
response = in.nextLine();
}
System.out.println();
System.out.println("Thank you for using the virtual dice.");
}
}

This is a great program to randomly roll die in COVID style!