Question

I'm having trouble writing my program in java, the issue is in my method called booleanArryayToString...

I'm having trouble writing my program in java, the issue is in my method called booleanArryayToString that takes a 2D Boolean array as input and returns a string;

for this method it is assumed that the Boolean true is represented by the Char 'x';

and that the Boolean false is represented by the Char "."

static String booleanArryayToString(boolean[][] panel{

return "replace"

}

for example if Boolean[][] panel = {{f,f,t,t,t,f,f,},{f,t,t,f,t,t,f,}}

it well return: ..xxx...xx.xx.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class BooleanArrayToString {

    static String booleanArrayToString(boolean[][] panel) {
        String result = "";
        for (int i = 0; i < panel.length; i++) {
            for (int j = 0; j < panel[i].length; j++) {
                if (panel[i][j]) {
                    result += 'x';
                } else {
                    result += '.';
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        boolean[][] panel = {{false, false, true, true, true, false, false,}, {false, true, true, false, true, true, false,}};

        System.out.println(booleanArrayToString(panel));
    }
}


Add a comment
Know the answer?
Add Answer to:
I'm having trouble writing my program in java, the issue is in my method called booleanArryayToString...
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
  • I'm writing a program in java called Sokoban. I'm pretty far in, but there are a...

    I'm writing a program in java called Sokoban. I'm pretty far in, but there are a few methods that I have no idea where to go from where I am now. Method 1: /**    * Moves a box on the board.    *    * Step 1: Use your checkDelta method to check that the move is valid. Recall that there are 2    * characters that can represent a box. Step 2: Use your togglePos method to correctly...

  • Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner...

    Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...

  • I'm writing a program in java that performs an interpolation search on an array of type...

    I'm writing a program in java that performs an interpolation search on an array of type double. I need a method that takes in that double array and a value to be searched for that is also of type double. I can find an implementation of the interpolation search that works with integer arrays but not with type double arrays. I need a method interpolationSearch(double[] arr, double searchValue) that returns the postion of where the value is if found and...

  • I'm having trouble with the daysSince() Method in bold at the end of the program public...

    I'm having trouble with the daysSince() Method in bold at the end of the program public class Date { static final int [] daysInMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; private int day, month, year; public Date() { day = 1; month = 1; year = 2000; } public Date(int d, int m, int y) { day = d; month = m; year = y; } public Date (String s) { setDate(s);...

  • Why is my java method returning "-1" even if the string is in the array? The...

    Why is my java method returning "-1" even if the string is in the array? The method is:        public static int findWord(String wordToFind {        boolean found=false;            int i=0;            while (i<words.length&& !found)                if (words[i]==wordToFind)                    found=true;                else i++;                if (found)                    return i;                else return -1;   ...

  • Hello, can someone please fix my code? It runs perfect but I'm having trouble with the...

    Hello, can someone please fix my code? It runs perfect but I'm having trouble with the index for the incorrect answer array; please run some tests to ensure the code runs properly, thank you! Here is the code: ___________________________________________________________________________________________________________________________ import java.util.Scanner; public class DriverTest{    final static int QuestionTotal = 10;    public static void main(String[] args){          // scanner and answer key        Scanner scan = new Scanner(System.in);        final char[] answers = {'A', 'B', 'C',...

  • I'm having trouble making a code for this problem, my class is working with java in...

    I'm having trouble making a code for this problem, my class is working with java in while loops and for loops. Write a method that returns true if an integer parameter n is a perfect number, false otherwise. (recall a perfect number is a number whose sum of its proper factors is equal to itself) (Precondition: n >= 1 .. means you are to presume n is positive) : EXAMPLE: 6 is a perfect number 1 2 3 equals 6...

  • (IN JAVA) Write a program named Review.java and implement the following methods: public static boolean isValidTicTacToeBoardString(String...

    (IN JAVA) Write a program named Review.java and implement the following methods: public static boolean isValidTicTacToeBoardString(String str) This method takes as its parameter a String that contains 9 characters representing the status of the Tic Tact Toe game. The String is mixed with X, O, x, o, and other letters. The first three letters represent the first row, letter 4 through letter 6 represent the second row, and the rest for the last row. To be considered as a valid...

  • I'm having trouble with my Java Homework in which my professor wants us to solve the...

    I'm having trouble with my Java Homework in which my professor wants us to solve the 0-1 Knapsack problem with Dynamic Programming. The code below is what she provided and she requested that we not change any of her existing code but simply add to it. As you can see she gave us the stub file for the knapsack class and the Item class. You are a thief with a knapsack with a carrying capacity of knapsackCapacity pounds. You want...

  • How to write a method in Java with these set of instructions: Method name will be:...

    How to write a method in Java with these set of instructions: Method name will be: public static boolean containsNumber(String[] array, String str) { // instruction: returns true if str is an element that is equal to an element of array // return false if str does not appear in array. // using compare String equality (str1.equals(str2). // JUST assume that array is not null and not empty // and NONE of strings in array is null. Assume str is...

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