Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Hw11P03
- {
- //inserting scanner class
- static Scanner input = new Scanner(System.in);
- //main method to print the array
- public static void main(String[] args)
- {
- String[][] array = makingArray();
- printingRandomArray(array);
- }
- //creating a random number generator to print x and os
- public static String[][] makingArray()
- {
- //asking for user input
- System.out.print("Enter matrix size: ");
- int sizeForRowsAndColumns = input.nextInt();
- //assigning the size to the array
- String[][] arr = new String[sizeForRowsAndColumns][sizeForRowsAndColumns];
- String xAndO = "";
- //loops to input random numbers into the array
- for(int row = 0; row < arr.length; row++)
- {
- for(int column = 0; column < arr[row].length; column++)
- {
- //creating the random number generator
- int randomNumber = (int)(2 * Math.random());
- //adding spaces in between the numbers
- if(randomNumber == 0)
- {
- xAndO = "" + randomNumber;
- xAndO = "o";
- }
- else
- {
- xAndO = "" + randomNumber;
- xAndO = "x";
- }
- arr[row][column] = xAndO;
- }
- }
- if(randomNumber = 0)
- //average formulas
- return arr;
- }
- //method to print the array
- public static void printingRandomArray(String[][] array)
- {
- for(int row = 0; row < array.length; row++)
- {
- for(int column = 0; column < array[row].length; column++)
- {
- System.out.print(array[row][column] + "\t");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement