fork(10) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. int gapInMinutes = 30 ; // Define your span-of-time.
  16. int loops = ( (int) Duration.ofHours( 24 ).toMinutes() / gapInMinutes ) ;
  17. List<LocalTime> times = new ArrayList<>( loops ) ;
  18.  
  19. LocalTime time = LocalTime.MIN ; // '00:00'
  20. for( int i = 1 ; i <= loops ; i ++ ) {
  21. times.add( time ) ;
  22. // Set up next loop.
  23. time = time.plusMinutes( gapInMinutes ) ;
  24. }
  25.  
  26. System.out.println( times.size() + " time slots: " ) ;
  27. System.out.println( times ) ;
  28.  
  29. }
  30. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
48 time slots: 
[00:00, 00:30, 01:00, 01:30, 02:00, 02:30, 03:00, 03:30, 04:00, 04:30, 05:00, 05:30, 06:00, 06:30, 07:00, 07:30, 08:00, 08:30, 09:00, 09:30, 10:00, 10:30, 11:00, 11:30, 12:00, 12:30, 13:00, 13:30, 14:00, 14:30, 15:00, 15:30, 16:00, 16:30, 17:00, 17:30, 18:00, 18:30, 19:00, 19:30, 20:00, 20:30, 21:00, 21:30, 22:00, 22:30, 23:00, 23:30]