Results 1 to 10 of 10
 04182010, 02:59 AM #1Member
 Join Date
 Feb 2010
 Posts
 26
 Rep Power
 0
cannot convert from int to int[][]
I need to "change all number n in the array by Mn, where M is the result of method Average applied on the input 2DArray."
I was given some partially completed code:
Java Code:public **** Modify(xxxx){ for(int i = 0; i < 10; i++){ for(int j = 0; j < 10; j++){ compute average for(int i = 0; i < 10; i++){ for(int j = 0; j < 10; j++){ { matrix[][] = m  matrix[][]; check if the value is < 0, if < 0 then make it positive SOP(.....); } } return matrix; }
Java Code:public static int[][] Modify(int [][] array1) { int sum = 0; for (int row = 0; row < array1.length; row++){ for (int col = 0; col < array1[row].length; col++){ sum = sum+array1[row][col];}} int average = sum / 100; for (int row= 0 ; row < array1.length; row++){ for (int col = 0; col < array1[row].length; col++){ array1 = average  array1[row][col]; if(array1[row][col] < 0)
Any ideas?
 04182010, 03:11 AM #2Member
 Join Date
 Mar 2010
 Posts
 88
 Rep Power
 0
Java Code:array1 = average  array1[row][col];
Java Code:array1[row][col] = average  array1[row][col];
 04182010, 03:11 AM #3Member
 Join Date
 Feb 2010
 Posts
 26
 Rep Power
 0
Yes, I just did that, thank you :).

I have to wonder about this line too:
Java Code:int average = sum / 100;
 04182010, 03:19 AM #5Member
 Join Date
 Mar 2010
 Posts
 88
 Rep Power
 0
inside of his given code he has:
Java Code:for(int i = 0; i < 10; i++){ for(int j = 0; j < 10; j++){
 04182010, 03:20 AM #6Member
 Join Date
 Mar 2010
 Posts
 88
 Rep Power
 0

 04182010, 04:26 AM #8Member
 Join Date
 Feb 2010
 Posts
 26
 Rep Power
 0
I used 100 because that's exactly the amount of numbers that are in the array. I don't know how to do it otherwise.
 04182010, 04:30 AM #9Member
 Join Date
 Mar 2010
 Posts
 88
 Rep Power
 0
okay but for safe measures, you can count the number of times it loops, or just use your loop conditions to know how many numbers have been added to sum.
if you KNOW 100% that it's a 10*10 array, then you should use 10 as your condition.
Also note that sum / 100 will always return an integer, but it does not round, it just drops the decimal. e.g 2.99 = 2. So you should probably say average = Math.round(sum / 100.0)

If your arrays are not ragged, then simply get the array1.length and array1[0].length and multiply the two. If the arrays are ragged, then create an int counter variable that's initialized to 0 and that gets incremented by one each time your nested for loop loops.
If you know that the arrays are of length 10, I'd still use the array lengths as noted above because next thing you know, you'll be instructed to make your method work with a 20x10 twodimensional array, and if you use lengths, you'll not have to change anything.
Similar Threads

convert XML using XSL
By rajjan4u in forum XMLReplies: 3Last Post: 11202009, 05:37 PM 
Convert to Int
By 6kyAngel in forum New To JavaReplies: 0Last Post: 03062009, 10:18 AM 
how to convert xml to xsd
By adi in forum XMLReplies: 2Last Post: 02122009, 03:43 PM 
need the help to convert to and from UTF8 and UCS2
By sachin_n in forum Advanced JavaReplies: 1Last Post: 01052009, 10:35 PM 
Convert to Applet
By Urgle in forum New To JavaReplies: 1Last Post: 11122008, 02:15 PM
Bookmarks