-3

I want to get a user input using a JOptionPane input box and split the user's input into 2 sections. (I'm a student so I have to use JOptionPane.) For example, I want to get the start time, 20:54, and split it to

startHour = 20;
startMin = 54;
Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175

1 Answers1

0

you can use the split function of String class which return an array of string values then index 0 contain the hour, index 1 contain the minutes:

note: you need to cast the string value to int

String value = "20:54";
String [] parts = value.split(":");
int startHour = Integer.parseInt(parts[0]);
int startMin = Integer.parseInt(parts[1]);
Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
Mustafa Poya
  • 2,051
  • 1
  • 13
  • 25