-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
  • 100,966
  • 191
  • 140
  • 197

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
  • 100,966
  • 191
  • 140
  • 197
Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36