How to draw a cool square in java? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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

28th Jan 2018, 3:59 AM
aiese
aiese - avatar
7 Réponses
+ 7
https://code.sololearn.com/cM9sz0rJ346F/?ref=app
28th Jan 2018, 12:41 PM
D_Stark
D_Stark - avatar
+ 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
28th Jan 2018, 12:29 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 14
//n×n square if row=1 or row=n // - else if column=1 or column=n // | else //" "
28th Jan 2018, 5:48 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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
28th Jan 2018, 12:38 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
D_Stark has solved. It worked on my computer and on my phone. https://code.sololearn.com/cM9sz0rJ346F/?ref=app
28th Jan 2018, 1:00 PM
aiese
aiese - avatar
+ 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.
28th Jan 2018, 12:18 PM
aiese
aiese - avatar
+ 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?
28th Jan 2018, 12:35 PM
aiese
aiese - avatar