daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Sep 13th, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. public class Practice {
  3.  
  4.     public static void main(String[] args) {
  5.         // TODO Auto-generated method stub
  6.         Scanner in = new Scanner(System.in);
  7.         System.out.print("Enter a time in HH:MM AM/PM format:");
  8.         String format = in.nextLine();
  9.         String[] parts = format.split(":");
  10.         String hours = parts[0];
  11.         String minuteparts = parts[1];
  12.         String periods = minuteparts.substring(3,5);
  13.         String minutes = minuteparts.substring(0,2);
  14.         int hours1 = Integer.parseInt(hours);
  15.         int minutes1 = Integer.parseInt(minutes);
  16.         if (periods.equals("PM")) {
  17.             hours1 = hours1 + 1200;
  18.             System.out.println("Time in military time is: " + hours1  + "" + minutes1);
  19.         }else {
  20.             System.out.println("Time in military time is: " + hours1  + "" + minutes1);
  21.            
  22.         }
  23.                
  24.     }
  25.  
  26. }
RAW Paste Data
Top