I am writing a simple program to convert a number into a word representing that number (13 => "thirteen").
I understand that I could get some words with a constant array of String as follows:
private static final String[] tensNames = {"", " ten", " twenty", " thirty", " forty", " fifty", " sixty", " seventy", " eighty", " ninety" };
... and access it with an index, but I wanted to try it using HashMap as follows:
final HashMap<Integer, String> tensNumberConversion = new HashMap<Integer, String>();
tensNumberConversion.put(2, "twenty");
tensNumberConversion.put(3, "thirty");
tensNumberConversion.put(4, "forty");
tensNumberConversion.put(5, "fifty");
tensNumberConversion.put(6, "sixty");
tensNumberConversion.put(7, "seventy");
tensNumberConversion.put(8, "eighty");
tensNumberConversion.put(9, "ninety");
I was instructed by the teacher to make these constants. Can a HashMap be a constant? As a beginner, it was not entirely clear how the terms “permanent” and “static” and “final” are related, and what exactly makes a constant. (static only? final one? static final together?).
Hashmap, IntelliJ ( 'private' ... "static" ).
. HashMap , ? !