The most banal question, but I can not find an answer to it. Enter the numbers that will be hours, minutes and seconds, how to display the result in one line in this form: 23:20:40 That is, using the colon character.

System.out.print("Введите значение H "); while ((h = scan.nextInt()) < 0 || h > 23) { System.out.println("Нужно ввести значение от 0 до 23 "); 
  • enter numbers like? Give a minimal example of code in which you enter numbers and indicate the place where you need to add the necessary code. - Komdosh

1 answer 1

Just concatenate strings:

 System.out.print(h+":"+m+":"+s); 
  • So simple, thanks a lot) - Reserveb
  • Is it really nice to display time in the form of, for example, 7:0:5 ? - m. vokhm February
  • @ m.vokhm ugly. Is there a solution for this? - Reserveb 3:06 pm
  • @Reserveb of course. System.out.format("%02d:%02d:%02d\n", h, m, s); - m. vokhm
  • @ m.vokhm Thank you! ) - Reserveb