Created
June 10, 2020 19:47
-
-
Save isu3ru/0c5838c171f83a94288e63be5760817f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package ceytechmarker.docx; | |
import java.util.HashMap; | |
import java.util.Scanner; | |
/** | |
* | |
* @author isuru | |
*/ | |
public class NumberAssign { | |
public static void main(String[] args) { | |
NumberAssign nas = new NumberAssign(); | |
Scanner sc = new Scanner(System.in); | |
System.out.print("Enter the number:"); | |
int number = sc.nextInt(); | |
String codeForNumber = nas.getCodeForNumber(number); | |
System.out.println("codeForNumber = " + codeForNumber); | |
} | |
/** | |
* Get the characters code for the given number | |
* | |
* @param String number Number as a string | |
* @return | |
*/ | |
private String getCodeForNumber(int number) { | |
HashMap<Character, Character> charMap = new HashMap<>(); | |
charMap.put('1', 'V'); | |
charMap.put('2', 'I'); | |
charMap.put('3', 'D'); | |
charMap.put('4', 'Y'); | |
charMap.put('5', 'A'); | |
charMap.put('6', 'R'); | |
charMap.put('7', 'T'); | |
charMap.put('8', 'H'); | |
charMap.put('9', 'E'); | |
charMap.put('0', 'S'); | |
StringBuilder sb = new StringBuilder(""); | |
for (char c : Integer.toString(number).toCharArray()) { | |
Character get = charMap.get(c); | |
if (null != get) { | |
sb.append(get); | |
} | |
} | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment