GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Notizen

Ohne Titel

ANGUE LIZETH LUQUE MAMANI Englisch 2 Seiten

Inhalt der Notizen (2)

Seite 1

Seite 2

main.java

public class Main { public static void main(String[] args){ TIEMPO TIEMPO1 = new TIEMPO(); TIEMPO1.setTiempo (13,50,5); System.out.println("hora en el sistema de 24 horas"); System.out.println("Hora: "+TIEMPO1.formato24h()); System.out.println(); System.out.println("hora en el sistema de 12 horas"); System.out.println(TIEMPO1.formato12h()); } }

tiempo.java

public class TIEMPO { private int hora; private int minuto; private int segundo; public void setTiempo (int hora, int minuto, int segundo) { if (hora<0 || hora>=24 || minuto<0 || minuto>=60 || segundo<0 || segundo>=60) throw new IllegalArgumentException(); this.hora=hora; this.minuto=minuto; this.segundo=segundo; } //metodo que muestra la hora en el sistema de 24h public String formato24h(){ return String.format("%02d:%02d:%02d", hora,minuto,segundo); } //metodo que muestra la hora en el sistema de 12h public String formato12h(){ return String.format("%d:%02d:%02d %s",((hora==0 || hora==12)?12 : hora%12),minuto,segundo,(hora<12 ? "AM" : "PM" )); } }

Informationen

Beschreibung
Notiz am Ohne Titel, erstellt von ANGUE LIZETH LUQUE MAMANI am 01/04/2024.
Erstellt von
ANGUE LIZETH LUQUE MAMANI · Apr 2024
Aktualisiert
1 Apr 2024
Aufrufe
0
Bewertung

Mehr zu Clases y objetos

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck