Question

b, 15 marks] write a method that generates an m n matrix with its elements filled in with X or o randomly. The method takes in two integer parameters m and n and returns a 2D array of characters.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the Matlab code for you:

function board = fillBoard(rows, cols)

% Write a method that generates an mxn matrix with its element filled in

% with X or O randomly. The method takes in two integer parameters m and

% n and returns a 2D array of characters.

values = ['X' 'O'];

for i = 1 : rows

for j = 1 : cols

board(i, j) = values(randi(2));

end

end

end

And the output screenshot is:

604.24 MB <D < >し令동啦) 99% E , Wed 12 Apr 02:48 ANANDA KUMAR THUMMAPUDI a MATLAB R2013a MATLAB Window Help EDITOR APPS Search

Add a comment
Know the answer?
Add Answer to:
Write a method that generates an m times m matrix with its elements filled in with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A method stub, or signature, is the first line of a method. Write a class that...

    A method stub, or signature, is the first line of a method. Write a class that contains the following “stubs” for methods used in measurement conversion. You do not have to implement the methods. Correct response: public void showMeters(int numMillimeters){} Write a method that takes two integers and displays their sum. Write a method that takes five doubles and returns their average. Write a method that returns the sum of two randomly generated integers. Write a method that takes three...

  • Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D...

    Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D arrays in Java. Create a single Java class Matrix and inside the class create the specified static methods as described Task # Description 1 Create a matrix (known components) 2 Create a matrix (random components) 3 Create a matrix from vectors 4 Compare two matrices 5 Add two matrices 6 Subtract two matrices 7 Multiply a matrix by a scalar 8 Multiply two matrices...

  • CST-117 In-Class Assignment 7 A method stub, or signature, is the first line of a method....

    CST-117 In-Class Assignment 7 A method stub, or signature, is the first line of a method. Write a class that contains the following “stubs” for methods used in measurement conversion. You do not have to implement the methods. Here’s an example: Write a void method that takes an integer for the number of millimeters and displays the number of meters. Correct response: public void showMeters(int numMillimeters){} Write a method that takes two integers and displays their sum. Write a method...

  • Write a method public static boolean FindSum (int[] a, int m) that takes an ascending sorted...

    Write a method public static boolean FindSum (int[] a, int m) that takes an ascending sorted array a with n distinct integers, and an integer m. If there are two elements in the array that add to be m, the method returns True; if not, it returns False. You may assume that the elements in the array are all distinct. There are several ways to solve this problem! (and some solutions are worth more points than others!) For 6 points,...

  • Write a JAVA PROGRAM with function named getData() that takes a matrix A and an integer...

    Write a JAVA PROGRAM with function named getData() that takes a matrix A and an integer "row" as input parameters and returns an array containing all elements in the given row of A.

  • Write a generic method gReplace() that takes a 2D array of generic elements and two scalars...

    Write a generic method gReplace() that takes a 2D array of generic elements and two scalars of the same type as the array elements. The function must replace all occurrences of the first scalar with the second one. (scalar: given int x, x is a scalar of type int) with java

  • write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative...

    write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative integer  n and a character  c and return a String consisting of n identical characters that are all equal to c. Write a method  named  printTriangle that receives two integer  parameters  n and k. If n is negative the method does nothing. If n happens to be an even number, itsvalue is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Create a class called Lab7b and in it implement all of the methods below. Also, write...

    Create a class called Lab7b and in it implement all of the methods below. Also, write a main method with test calls to all of these methods. Don’t forget to turn in your file to Canvas before the end of the lab today. int[][] random(int N, int start, int end) returns an N-by-N matrix of random integers ranging from start to end; int rowSum(int[][] a, int i) returns the sum of the elements in row i of the 2-D array...

  • Write A JAVA mergesort method that mergesorts array elements in descending order. Write A JAVA binary...

    Write A JAVA mergesort method that mergesorts array elements in descending order. Write A JAVA binary search method that searches x in a sorted array with n elements and returns its position if exist, -1 otherwise.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT