The title sounds simple but it's a bit more complicated. This is for an entry level Java class so excuse the lack of use of methods and whatnot!
Essentially, we want the user to create the size of their array, and then print out a random assortment of either spaces or blocks. This is what I have so far.
What I don't know how to do is print out either the space or the block according to the user-determined size of the array. Any help is appreciated!
import java.util.Scanner;
import java.util.Random;
public class ArtLab {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to the 2D art generator!");
System.out.println("Lets define the size of your canvas.");
System.out.println("Please enter your x:");
int x = input.nextInt();
System.out.println("Please enter your y:");
int y = input.nextInt();
input.nextLine();
char[][] canvasSize = new char[x][y];
for (int row = 0; row < x; row++)
{
for (int col = 0; col < y; col++)
{
canvasSize[row][col] = ' ';
}
}
for (int row = 0; row < x; row++)
{
for (int col = 0; col < y; col++)
{
canvasSize[row][col] = '█';
}
}
for(int row = 0; row < x; row++)
{
for(int col = 0; col < y; col++)
{
System.out.print(canvasSize[row][col]);
}
System.out.println();
}
if(x <= 0 || y <= 0)
{
System.out.println("Invalid input!");
System.exit(0);
}
}
}