Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Scanner;
- public class LetterIndex {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- char[] arr = "a b c d e f g h i j k l m n o p q r s t u v w x y z".toCharArray();
- System.out.println("Input text: ");
- String text = scan.nextLine();
- HashMap<Character, Integer> map = new HashMap();
- for (int i = 0; i < arr.length; i++) {
- map.put(arr[i], i);
- }
- for (int i = 0; i < text.length(); i++) {
- System.out.println(text.charAt(i) + " -> " + map.get(text.charAt(i)));
- }
- }
- }
Add Comment
Please, Sign In to add comment