problem with if statement and logical operator
package time;
import java.util.*;
public class Changetime {
@SuppressWarnings("resource")
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
boolean r = true;
while (r==true)
{
System.out.println("Enter time as h:m:s AM/PM");
int h=scan.nextInt();
int m=scan.nextInt();
int s=scan.nextInt();
String t=scan.nextLine();
System.out.println("time entered is => "+(String.format("%02d",h)) +":" +(String.format("%02d",m))+":"+(String.format("%02d",s)) +t );
if (h<12 && t.equalsIgnoreCase("pm"))
{
h=h+12;
System.out.println("\n your 24 hr format time is " +(String.format("%02d",h)) +":" +(String.format("%02d",m))+":"+(String.format("%02d",s))+" hrs");
}
if (h==12 && t.equalsIgnoreCase("am"))
{h=h-12;
System.out.println("\n your 24 hr format time is " +(String.format("%02d",h)) +":" +(String.format("%02d",m))+":"+(String.format("%02d",s))+" hrs");
}
}
}
}
its a program to change time into 24 hr format, its not checking statements at if condition its compiling but during run time its not processing the conditions ...tell me whats wrong.
Aucun commentaire:
Enregistrer un commentaire