Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Hw11P03
  4. {
  5. //inserting scanner class
  6. static Scanner input = new Scanner(System.in);
  7. //main method to print the array
  8. public static void main(String[] args)
  9. {
  10. String[][] array = makingArray();
  11. printingRandomArray(array);
  12.  
  13. }
  14.  
  15. //creating a random number generator to print x and os
  16. public static String[][] makingArray()
  17. {
  18.  
  19. //asking for user input
  20. System.out.print("Enter matrix size: ");
  21. int sizeForRowsAndColumns = input.nextInt();
  22.  
  23. //assigning the size to the array
  24. String[][] arr = new String[sizeForRowsAndColumns][sizeForRowsAndColumns];
  25. String xAndO = "";
  26.  
  27. //loops to input random numbers into the array
  28. for(int row = 0; row < arr.length; row++)
  29. {
  30. for(int column = 0; column < arr[row].length; column++)
  31. {
  32. //creating the random number generator
  33. int randomNumber = (int)(2 * Math.random());
  34. //adding spaces in between the numbers
  35. if(randomNumber == 0)
  36. {
  37. xAndO = "" + randomNumber;
  38. xAndO = "o";
  39. }
  40. else
  41. {
  42. xAndO = "" + randomNumber;
  43. xAndO = "x";
  44. }
  45. arr[row][column] = xAndO;
  46. }
  47. }
  48. if(randomNumber = 0)
  49. //average formulas
  50.  
  51. return arr;
  52. }
  53.  
  54. //method to print the array
  55. public static void printingRandomArray(String[][] array)
  56. {
  57. for(int row = 0; row < array.length; row++)
  58. {
  59. for(int column = 0; column < array[row].length; column++)
  60. {
  61. System.out.print(array[row][column] + "\t");
  62. }
  63. System.out.println();
  64.  
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement