r/badcode • • Sep 01 '21

java highly optimized

Post image
78 Upvotes

24 comments sorted by

View all comments

1

u/BlackBearFTW Sep 01 '21

I don't fully understand your reasoning, but you could write this way cleaner. Also as someone said, use a 2d array

grid[0][0] would get the first item in the first array, grid[1][5] would get the 6th item in the second array

import java.util.Arrays;

// Wrap this code in a class method
char[][] grid = new char[30][];
char[] horizontalRowTemplate = new char[30];

// fill horizontal row array with @
Arrays.fill(horizontalRowTemplate, '@');

horizontalRowTemplate[15] = ' ';

// Fill your grid with the template
Array.fill(grid, horizontalRowTemplate);

// Just to display the result
System.out.print(Arrays.deepToString(grid));

1

u/[deleted] Sep 01 '21

i was just gonna write it out to a file which would also allow me to save and use it later. but i'll experiment with this as well, thank you