Here, it translates the line with numbers into letters, only there are no errors yet, but it copes with the task.
public class Main { private static Map<Character, Integer> hm = new HashMap<>(); private static Scanner in; public static void main(String[] args) { hm.put('a', 1); hm.put('b', 2); hm.put('c', 3); hm.put('d', 4); hm.put('e', 5); hm.put('f', 6); hm.put('g', 7); hm.put('h', 8); hm.put('i', 9); hm.put('j', 10); hm.put('k', 11); hm.put('l', 12); hm.put('m', 13); hm.put('n', 14); hm.put('o', 15); hm.put('p', 16); hm.put('q', 17); hm.put('r', 18); hm.put('s', 19); hm.put('t', 20); hm.put('u', 21); hm.put('v', 22); hm.put('w', 23); hm.put('x', 24); hm.put('y', 25); hm.put('z', 26); printText(); } private static void printValue() { in = new Scanner(System.in); String user = in.nextLine(); for (char letter : user.toCharArray()) { for (char key : hm.keySet()) { if (letter == key) { System.out.print(hm.get(key)); System.out.print(" "); } } } in.close(); } private static void printText() { System.out.println("вводить цифры через пробел"); in = new Scanner(System.in); String user = in.nextLine(); in.close(); ArrayList<String> strings = new ArrayList<>(); ArrayList<Integer> integers = new ArrayList<>(); char[] elements = user.toCharArray(); String current = ""; for (char element : elements) { if (element == ' ') { strings.add(current); current = ""; } else { current += Character.toString(element); } } strings.add(current); for (String element : strings) { integers.add(Integer.parseInt(element)); } strings.clear(); ArrayList<Character> result = new ArrayList<>(); for (Integer element : integers) { for (Map.Entry<Character, Integer> entry : hm.entrySet()) { if (entry.getValue().equals(element)) { result.add(entry.getKey()); } } } System.out.println(result); } }
Later I can write more shortly. dirty option in general), but working. Digits are entered through a space.
hm.get(key)=) after makingInteger.parseInt(тутЧислоВведенноеПользователем);- Alexey Shimanskykey - 'a' + 1does the same. - pavel