I want the code to print 3 lines of '@' with the same length.
In the second line it will have text inside. I have a problem when [text%2] != 0.
Tried to fix it with a for loop, but it will print 1 less or more '@' when [text % 2] = 1.
If something isn't clear please ask me to explain, thanks a lot to helpers.
package sos; public class triangle { public static void main(String[] args) { int x,y,z = 5; //z*2 = first and second lines / total.length char w = '@'; for (int j=0; j<z*2; j++) { //first line System.out.print(w); } System.out.println(); String txt = " 312 "; x = txt.length(); y = x/2; z-=y; for (int i = 0; i < z; i++) { // second line (first half) System.out.print(w); } System.out.print(txt.toUpperCase()); //middle TEXT if (z%2==0) { //second line (second half) for (int i = 1; i < z; i++) { System.out.print(w); } } else { for (int i = 0; i < z; i++) { System.out.print(w); } } System.out.println(); z+=y; for (int j=0; j<z*2; j++) { //last line System.out.print(w); } System.out.println(); System.out.println(txt.length()); int d = txt.length(); d%=2; System.out.println(d); } }