Q:

Write a Java program to print the contents of a two-dimensional Boolean array where t will represent true and f will represent false

0

 Write a Java program to print the contents of a two-dimensional Boolean array where t will represent true and f will represent false

Sample array:
array = {{true, false, true},
{false, true, false}};
Expected Output :
t f t
f t f

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {

		boolean[][] array = {{true, false, true},

							 {false, true, false}};

		int rows_length = array.length;

		int columns_length = array[0].length;

		

		for (int i = 0; i < rows_length; i++) {

			for (int j = 0; j < columns_length; j++) {

				

				if (array[i][j]) {

					System.out.print(" t ");

				} else {

					System.out.print(" f ");

				}

				

			}

			System.out.println();

		}	

    }

}

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {

		boolean[][] array = {{true, false, true},

							 {false, true, false}};

		int rows_length = array.length;

		int columns_length = array[0].length;

		

		for (int i = 0; i < rows_length; i++) {

			for (int j = 0; j < columns_length; j++) {

				

				if (array[i][j]) {

					System.out.print(" t ");

				} else {

					System.out.print(" f ");

				}

				

			}

			System.out.println();

		}	

    }

}

Sample Output:

 t  f  t 
 f  t  f 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now