Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static String indefinite(String s, int qty) { if (qty == 1) { if ("AEIOUYaeiouy".contains(s.substring(0, 1))) return "an " + s; else return "a " + s; } else { return String.valueOf(qty) + " " + plural(s); } } public static String plural(String s) { if (s.endsWith("y")) return s.substring(0, s.length() - 1) + "ies"; else if (s.endsWith("us")) return s.substring(0, s.length() - 2) + "i"; else if (s.endsWith("ch") || s.endsWith("x") || s.endsWith("s") || s.endsWith("sh")) return s + "es"; else if (s.endsWith("f")) return s.substring(0, s.length() - 1) + "ves"; else if (s.endsWith("man") || s.endsWith("Man")) return s.substring(0, s.length() - 2) + "en"; else return s + "s"; } }