Saturday, 3 September 2011

this Pointer in java


class time
{
private int hour=1,min=2,sec=3;
public void setTime(int hour, int min, int sec)
{
this.hour=hour;
this.min=min;
this.sec=sec;
}
public String toMilitary()
{
return String.format("%02d:%02d:%02d %s", hour, min, sec, "hour");
}
public String toRegular()
{
return String.format("%d:%02d:%02d %s", ((hour==0||hour==12)?12:hour%12), min, sec, (hour<12)?"am":"pm");
}
}
class abc
{
public static void main(String args[])
{
time obj=new time();
System.out.println(obj.toMilitary());
System.out.println(obj.toRegular());
obj.setTime(7,8,9);
System.out.println(obj.toMilitary());
System.out.println(obj.toRegular());
}
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.