Denis_Hristov

LetterIndex

Jun 8th, 2021 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3.  
  4. public class LetterIndex {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.  
  8.         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();
  9.         System.out.println("Input text: ");
  10.         String text = scan.nextLine();
  11.         HashMap<Character, Integer> map = new HashMap();
  12.  
  13.         for (int i = 0; i < arr.length; i++) {
  14.             map.put(arr[i], i);
  15.         }
  16.  
  17.         for (int i = 0; i < text.length(); i++) {
  18.             System.out.println(text.charAt(i) + " -> " + map.get(text.charAt(i)));
  19.         }
  20.     }
  21. }
  22.  
Add Comment
Please, Sign In to add comment