Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.Scanner; public class OutputArray { // main method creates array named data 100x100 public static void main(String[] args) { Scanner sc = new Scanner
import java.util.Scanner; public class OutputArray { // main method creates array named data 100x100 public static void main(String[] args) { Scanner sc = new Scanner (System.in); String[][] data = new String [100][100]; // takes user input for rows and columns, stores in int variables rows, cols System.out.print("Enter number of rows."); int rows = sc.nextInt(); System.out.print("Enter number of columns."); int cols = sc.nextInt(); // ex. rows is 4 and cols is 2... //fills selected subarray with random letter of alphabet... how to resolve valueOf? System.out.println("Original 2D array:"); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { int index = (int) (Math.random() *26); char letter = (char) ('A' + index); data [i][j] = String.valueOf(letter); System.out.print(data[i][j] + " "); } System.out.println(); } System.out.println("Combinations:"); printCombinations(data, 0, rows, cols, ""); } // calls printCombinations method... passes array, current row start at 0? // rows, cols, current Output??? just a blank space? or... ??? // I don't understand how the section below works... public static void printCombinations(String[][] data, int currRow, int maxRows, int maxCols, String currentOutput) { if (currRow >= maxRows) { System.out.println(currentOutput); return; } for (int i = 0; i < maxCols && i < data[currRow].length; i++) { printCombinations(data, currRow +1, maxRows, maxCols, currentOutput + data[currRow][i] + " "); } } }
When I copy this program, it gives me three errors. Could someone explain how to fix this?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started