+ 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 Réponses
+ 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?