[JAVA] Memorandum No. 3 "Replace the entered character string for each character depending on the conditions"

Introduction

Creating so-called Leet notation

What you want to do

  1. Enter one character string (any number of characters)
  2. Judge each character and perform conversion
  3. Output the converted character string

code

        public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        List<Character>list = new ArrayList<>();
        for(int i = 0; i < s.length(); i++) {
            list.add(s.charAt(i));//Add the entered character string to the Character type list character by character
        }

        for(int i = 0; i < s.length(); i++) {
            char c = list.get(i);
            switch(c) {
            case 'A':
                list.set(i, '4');
                break;

            case 'E':
                list.set(i, '3');
                break;

            case 'G':
                list.set(i, '6');
                break;

            case 'I':
                list.set(i, '1');
                break;

            case 'O':
                list.set(i, '0');
                break;

            case 'S':
                list.set(i, '5');
                break;

            case 'Z':
                list.set(i, '2');
                break;
            }
        }

        for(char word : list) {
            System.out.print(word);
        }
    }

Recommended Posts

Memorandum No. 3 "Replace the entered character string for each character depending on the conditions"
Note No. 6 "Calculate the formula for the one-digit sum difference received as a character string" [Java]
Memorandum No.4 "Get a character string and decorate it" [Java]