+ 9
How to draw a cool square in java?
So, I want to draw a square using java, but for a console. I have to use characters to draw the sides and the results is weird, like: #### _____ ***** # # | | * * # # | | * * #### |____| ***** I would like to draw a real square? Help, please. Look my code: https://code.sololearn.com/c43yejVcx87O/?ref=app
7 Antworten
+ 7
https://code.sololearn.com/cM9sz0rJ346F/?ref=app
+ 15
for making it perfect , horizontal space taken by " " must be equal to or in some small natural number ratio with that of special character
//so that u can identify how much space u need for how much side length
//by fixing number of " " that can be printed after seeing side length
đđđsee how many of that special character takes space taken by some number of " " & then use that ratio
+ 14
//nĂn square
if row=1 or row=n // -
else if column=1 or column=n // |
else //" "
+ 13
haha , then it can only be solved by using characters taking same size of that of space " " in device
or
by using same character
+ 3
D_Stark has solved. It worked on my computer and on my phone.
https://code.sololearn.com/cM9sz0rJ346F/?ref=app
+ 2
So, I solved the problem using special characters like these (value and character):
191 â 192 â 193 ⎠194 ⏠195 â 196 â 197 ⌠198 â 199 â 200 â 201 â 202 â© 203 ⊠204 â 205 â 206 ⏠207 ⧠208 âš 209 †210 â„ 211 â 212 â 213 â 214 â 215 â« 216 âȘ 217 â
So I can draw:
âââââââââ
â â
â â
â â
âââââââââ
You can see that I have bugs yet. Its because the length of the character space/blank is less than "â". If I would had an command like "gotoxy" from C++ in Java I had alread solved it.
I would fill with a character with the same length, but it is not elegant.
âââââââââ
â___________â
â___________â
â___________â
âââââââââ
See now how the code is working. It is better on the computer than in a mobile phone.
+ 2
Great. But still have a problem the size of the characters is diferent in diferents systems, then the result is difent. If you run the code in a computer the square is perfect, but in the smartphone.
I wonder, are there how identify the device from the code?