-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek1b.java
More file actions
25 lines (24 loc) · 789 Bytes
/
week1b.java
File metadata and controls
25 lines (24 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Scanner;
public class week1b {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the time like this :e.g. 07:05:45PM:");
String x = sc.nextLine();
String[] time = x.split(":");
int hrs = Integer.parseInt(time[0]);
int mins = Integer.parseInt(time[1]);
int secs = Integer.parseInt(time[2].substring(0, 2));
String mer = time[2].substring(2, 4);
if (mer.equalsIgnoreCase("PM")) {
if (hrs != 12) {
hrs = hrs + 12;
}
}
if (mer.equalsIgnoreCase("AM")) {
if (hrs == 12) {
hrs = 0;
}
}
System.out.print(hrs+ ":"+mins+":"+secs);
}
}