Memorandum No.4 "Get a character string and decorate it" [Java]

What you want to do

  1. Receive one character string of any number of characters
  2. Output with the appearance of surrounding the received character string with "+"

Example. If you receive the string "SUN"

+++++ +SUN+ +++++

code

        Scanner sc = new Scanner(System.in);
        String word = sc.nextLine();
        int wordNum = word.length();//Number of characters in a word
        int lineNum = wordNum + 2;//Number of characters required to enclose a word

        Character [][] plus = new Character[3][lineNum];//
        for(int i = 0; i < plus.length; i ++) {
            for(int j = 0; j < plus[i].length; j++) {
                plus[i][j] = '+';
                for(int k = 0; k < word.length(); k++) {
                    int l = k + 1;
                    plus[1][l] = word.charAt(k);//Extract the letters of the word one by one in a loop and update the elements to be enclosed
                }
                System.out.print(plus[i][j]);
            }
            System.out.println("");
        }

Impressions

I feel like I've made it quite a bit. I tried using a triple loop (or rather), but I didn't know if I would use it like this, so I used it.

Recommended Posts

Memorandum No.4 "Get a character string and decorate it" [Java]
Get an image as a character string (resource name) and paste it into ImageView (kotiln)
Memorandum No.2 "Making a search history with ArrayList and HashSet" [Java]
[Java] Divide a character string by a specified character
[Java] Difference between equals and == in a character string that is a reference type
[Java] String comparison and && and ||
Write a class in Kotlin and call it in Java
[Java] How to cut out a character string character by character
[Java] How to erase a specific character from a character string
[Java] Handling of character strings (String class and StringBuilder class)
[Java] Cut out a part of the character string with Matcher and regular expression
[Java] Throw a request and display the screen ② (GET / POST)
Note No. 6 "Calculate the formula for the one-digit sum difference received as a character string" [Java]
[Java] Throw a request and display the screen (GET / POST)
[Java] How to convert a character string from String type to byte type
[Java] About String and StringBuilder
[Java] Make it a constant
[Kotlin] Get Java Constructor / Method from KFunction and call it
[Java] How to use substring to cut out a character string
Java Language Feature and How it Produced a Subtle Bug
Code to specify the image name as a character string and paste it into ImageView (android)
[Ruby] Difference between symbol variables and character string variables. About the difference between [: a] and ['a'].
Java, JS (jQuery) and Ajax. Get a specific value of JSON.
[Java] How to convert from String to Path type and get the path
Get stuck in a Java primer
Studying Java 8 (String Joiner and join)
[Java] Get Json from URL and handle it with standard API (javax.script)
Memorandum No. 3 "Replace the entered character string for each character depending on the conditions"
[Java] How to use substring to cut out a part of a character string
[Java] How to get to the front of a specific string using the String class
I wrote a Lambda function in Java and deployed it with SAM
A look at Jenkins, OpenJDK 8 and Java 11
[Creating] A memorandum about coding in Java
A Java engineer compared Swift, Kotlin, and Java.
[Java] Character judgment / character string formatting (AOJ11 --character count)
Split a string with ". (Dot)" in Java
[Java] Comparison of String type character strings
[Java8] Search the directory and get the file
[Java] How to easily get the longest character string of ArrayList using stream
How to ZIP a JAVA CSV file and manage it in a Byte array
[Java] When putting a character string in the case of a switch statement, it is necessary to make it a constant expression
I want to find the MD5 checksum of a file in Java and get the result as a string in hexadecimal notation.