im trying to make a dice roller that can take a single input and roll a die with a certain number of sides a certain number of times. so if I input "2d4" itll roll a 4 sided die 2 times, and give me both results separately. To do this ive been trying to use the scanner class since im rather new to programming. Im trying to take it step by step and use what I know. Im sure there are better classes to use and such but Im trying to do it with scanner specifically.
import java.util.Scanner;
import java.util.Random;
public class DiceRoller3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Random Random = new Random();
char NumberOfDice = input.next().charAt(0);
char DieType = input.next().charAt(2);
This, i believe is causing me to have to create two inputs, due to it searching for the "next" input to look for a character in. I would like to be able to do it with one input, is there a way to do that?
You can use the nextLine method of Scanner class
String userInput = input.nextLine();
char noOfDie = userInput.charAt(0);
char dieType = userInput.charAt(2);
The method returns a string of a complete line entered by the user. Works by giving your input and pressing enter.