Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Monday

JAVA PROGRAMMING TUTORIAL 30: TIME DISPLAY

public class HackDefence{

public static void main(String[]args){
HackDefence timeObject = new HackDefence();

System.out.println("Default time :" + timeObject.displayTime());

timeObject.setTime(18,9,7);

System.out.println("Time After new input :"+timeObject.displayTime());

}

private int hour;

private int minute;

private int second;
public void setTime(int h, int m, int s){

hour = ((h>=0 && h<24)? h:0);

minute = ((m>=0 && m<60)? m:0);

second = ((s>=0 && s<60)? s:0);
}

public String displayTime(){

return String.format("%02d:%02d:%02d",hour,minute,second);

}
    }

OUTPUT:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...