From 67393f42f41ab92219deb549f711121c4dab845b Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sun, 15 Dec 2019 10:34:58 +0700 Subject: [usth/ICT2.2] Object Oriented Programming --- usth/ICT2.2/labwork/1/Hellos.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 usth/ICT2.2/labwork/1/Hellos.java (limited to 'usth/ICT2.2/labwork/1/Hellos.java') diff --git a/usth/ICT2.2/labwork/1/Hellos.java b/usth/ICT2.2/labwork/1/Hellos.java new file mode 100644 index 0000000..206ac58 --- /dev/null +++ b/usth/ICT2.2/labwork/1/Hellos.java @@ -0,0 +1,14 @@ +class Hellos +{ + private static final String[] TH = {"th", "st", "nd", "rd", "th", + "th", "th", "th", "th", "th"}; + + public static void main(String... args) + { + int n = Integer.parseInt(args[0]); + for (int i = 1; i <= n; ++i) + // Before one says this defeat the purpose of the section, + // the tertiary operator IS conditional. + System.out.println(i + TH[i % 100 / 10 == 1 ? 7 : i % 10] + " Hello"); + } +} -- cgit 1.4.1