Example. If you receive the string "SUN"
+++++ +SUN+ +++++
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("");
}
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