multidimensional-array

Can someone help me assign multiple string arrays into one 2d string array?

為{幸葍}努か 提交于 2021-02-05 07:25:27
问题 In C#, can someone help me assign multiple string arrays to a 2d string array? Here is my code: string[] test1 = new string[5] { "one", "two", "three", "four", "five" }; string[] test2 = new string[5] { "one", "two", "three", "four", "five" }; string[] test3 = new string[5] { "one", "two", "three", "four", "five" }; string[] test4 = new string[5] { "one", "two", "three", "four", "five" }; string[,] allTestStrings = new string [4, 5]; allTestStrings[0] = test1; allTestStrings[1] = test2;

How to sum a row in a matrix

不问归期 提交于 2021-02-05 06:54:06
问题 Write the method: public int sumRow(int[][] matrix, int row) that sums row row in the 2D array called matrix. Given: public void run() { System.out.println(sumRow(new int[][]{{70,93,68,78,83},{68,89,91,93,72},{98,68,69,79,88}}, 2)); System.out.println(sumRow(new int[][]{{1,1,1}, {2,2,2}, {3,3,3}}, 0)); System.out.println(sumRow(new int[][]{{2,4,6,8,10}, {1,2,3,4,5}, {10,20,30,40,50}}, 2)); } So far I have: public int sumRow(int[][] matrix, int row) { int sum = 0; for(int i = 0; i < matrix

How to sum a row in a matrix

拟墨画扇 提交于 2021-02-05 06:54:04
问题 Write the method: public int sumRow(int[][] matrix, int row) that sums row row in the 2D array called matrix. Given: public void run() { System.out.println(sumRow(new int[][]{{70,93,68,78,83},{68,89,91,93,72},{98,68,69,79,88}}, 2)); System.out.println(sumRow(new int[][]{{1,1,1}, {2,2,2}, {3,3,3}}, 0)); System.out.println(sumRow(new int[][]{{2,4,6,8,10}, {1,2,3,4,5}, {10,20,30,40,50}}, 2)); } So far I have: public int sumRow(int[][] matrix, int row) { int sum = 0; for(int i = 0; i < matrix

java multi-dimensional array fails with a nullpointerexception

佐手、 提交于 2021-02-04 21:37:18
问题 I get nullpointerexception when I try to fill a 2D array with process IDs, it is 2D since there is a unlimited list of PIDs for each system and I need to eventually return that back to my main code (set to void now since just a prototype test function). Any ideas would be great private void testfunctionA (List<String> additionalPC) { // A 2d array that will contain a list of pids for each system - needs to be strings and not integers String[][] pidCollection = new String[additionalPC.size()][

PHP 7 array columns not working for multidimensional array

倖福魔咒の 提交于 2021-02-04 21:33:54
问题 Below is my array structure: Array ( [2016-09-01] => Array ( [1] => Array ( [hours_type_id] => 1 [date] => 2016-09-01 [hours] => 8.00 [ts_weekly_id] => 53428 ) [2] => Array ( [hours_type_id] => 2 [date] => 2016-09-01 [hours] => 0.00 [ts_weekly_id] => 53428 ) [10] => Array ( [hours_type_id] => 10 [date] => 2016-09-01 [hours] => 0.00 [ts_weekly_id] => 53428 ) ) I am trying to get all hours column in another array. Below is the code: $billcols = array_column($billhours, "hours"); Is there any

Stream 2d array, trim values and collect back to 2d array

怎甘沉沦 提交于 2021-02-04 21:16:26
问题 Any idea how to perform a trim operation on a 2d array of strings e.g. 3x3 using Java stream API and collect one back to same dimension 3x3 array? The point is to avoid using explicit for loops. The current solution would be simply to do a for loop like: String arr[][] = { {" word ", " word "}, {" word ", " word "}, {" word ", " word "}}; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { arr[i][j] = arr[i][j].trim(); } } And that works, but I'm trying to come up

Stream 2d array, trim values and collect back to 2d array

大憨熊 提交于 2021-02-04 21:14:46
问题 Any idea how to perform a trim operation on a 2d array of strings e.g. 3x3 using Java stream API and collect one back to same dimension 3x3 array? The point is to avoid using explicit for loops. The current solution would be simply to do a for loop like: String arr[][] = { {" word ", " word "}, {" word ", " word "}, {" word ", " word "}}; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { arr[i][j] = arr[i][j].trim(); } } And that works, but I'm trying to come up

Stream 2d array, trim values and collect back to 2d array

喜夏-厌秋 提交于 2021-02-04 21:13:09
问题 Any idea how to perform a trim operation on a 2d array of strings e.g. 3x3 using Java stream API and collect one back to same dimension 3x3 array? The point is to avoid using explicit for loops. The current solution would be simply to do a for loop like: String arr[][] = { {" word ", " word "}, {" word ", " word "}, {" word ", " word "}}; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { arr[i][j] = arr[i][j].trim(); } } And that works, but I'm trying to come up

Find parents key in PHP array

早过忘川 提交于 2021-02-04 16:33:25
问题 I am looking for a method to find all parents of a multidimensional PHP array I have this following array: Array ( [files] => Array ( [a] => Array ( [ab] => Array ( [0] => ab.jpg ) [0] => abc.jpg ) [b] => Array ( [ba] => Array ( [bab] => Array ( [0] => abc.jpg ) [bac] => Array ( [0] => abd.jpg ) [0] => ade.jpg ) ) [c] => Array ( [cb] => Array ( [0] => abf.jpg ) ) ) ) I want to find Parents by key, for example, To find all parents of key: 'bac' It should return: files->b->ba->bac Any

how to display in descending order a two dimensional array

为君一笑 提交于 2021-01-29 22:40:41
问题 I want to link and sort in descending order a two dimensional array. I coded my program in a way so that you can print the array but it is not sorted. How can I make it sorted? This is a program to calculate the number of hours worked by 8 employees during the week (7 days), and print them out in descending order: public class WeeklyHours { public static void main(String[] args) { double[][] employeeWorkHours = { { 2, 4, 3, 4, 5, 8, 8 }, { 7, 3, 4, 3, 3, 4, 4 }, { 3, 3, 4, 3, 3, 2, 2 }, { 9,