同じプログラムのJavaバージョン。Time APIを使っているのでJava8以降で。
TzijonikMain.java
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 26 27 28 29 30 31 32 33 34 |
import java.time.*; public class TzijonikMain { public static void main(String[] args) { String name = "Kotzij"; String formalName = "Kotz'ij"; String prompt = name + "> "; LocalTime currentTime = LocalTime.now(); int hour = currentTime.getHour(); String saludo; if(hour > 3 && hour <12){ saludo = "Saqarik"; } else if (hour >= 12 && hour < 18){ saludo = "Xe'q'ij"; } else{ saludo = "Xokaq'ab'"; } System.out.println("Tzijonik: Version 1.0 (20170503)"); System.out.println(prompt + saludo); System.out.println(prompt + "In al " + formalName); while(true){ System.out.print("> "); String userInput = new java.util.Scanner(System.in).nextLine(); if (userInput.equals("")){ break; } System.out.println(prompt + "Jas " + userInput + "?"); } } } |