Results 1 to 3 of 3
Thread: Help with Two Dimensional Array
- 06-03-2011, 07:59 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 18
- Rep Power
- 0
Help with Two Dimensional Array
Okay so I have a two dimensional array and I am trying to find out how many even numbers have been generated, and I need to display the count. Below I started trying to create a method for findEven but ran into some problems with it when I tried to compile. Im not sure if I wrote the method correctly. Any help would greatly be appreciated.
Java Code:import java.util.*; import java.math.*; public class twodim { public static void (findEven) for (x = 2; x<= 20; x = x + 2) { System.out.println( x ); } for (y = 2; y<= 20; y = y + 2) { System.out.println( y ); } public static void main(String[] args) { final int row = 4; final int col = 4; Random rand = new Random(); int [][] twoDarray = new int [row][col]; for (int x = 0; x < twoDarray.length; x++) { for (int y = 0; y < twoDarray[x].length; y++) { twoDarray[x][y] = rand.nextInt(1000); } } for(int i = 0; i < twoDarray.length; i++) { for(int j = 0; j < twoDarray[i].length; j++) { System.out.print(twoDarray[i][j] + " "); } System.out.println(); } } }
- 06-03-2011, 08:18 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Oohhhh ...
public static void (findEven)
for (x = 2; x<= 20; x = x + 2) {
this is not a java syntax :)
Look here:
Java Code:import java.util.Random; public class twodim { public static void findEven() { for (int x = 2; x <= 20; x = x + 2) { System.out.println(x); } for (int y = 2; y <= 20; y = y + 2) { System.out.println(y); } } public static void main(String[] args) { final int row = 4; final int col = 4; Random rand = new Random(); int[][] twoDarray = new int[row][col]; for (int x = 0; x < twoDarray.length; x++) { for (int y = 0; y < twoDarray[x].length; y++) { twoDarray[x][y] = rand.nextInt(1000); } } for (int i = 0; i < twoDarray.length; i++) { for (int j = 0; j < twoDarray[i].length; j++) { System.out.print(twoDarray[i][j] + " "); } System.out.println(); } } }
- 06-03-2011, 08:22 PM #3
Which tells us absolutely NOTHING.
And your code is in very bad shape. Where is the method name? Inside brackets? No opening/closing braces for method. Where have you declared the x and y variables that you are using inside your for loop?
Read some basic stuff first : Trail: Learning the Java Language
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
Similar Threads
-
2 dimensional array
By sehudson in forum New To JavaReplies: 5Last Post: 02-20-2011, 11:56 PM -
2 dimensional array help!
By ber1023 in forum New To JavaReplies: 9Last Post: 01-02-2011, 12:29 AM -
Two dimensional array
By niu_niu in forum New To JavaReplies: 4Last Post: 06-13-2010, 12:34 AM -
about two dimensional array
By matin1234 in forum New To JavaReplies: 2Last Post: 06-01-2010, 11:09 AM -
two-dimensional array
By kHim in forum New To JavaReplies: 4Last Post: 11-16-2008, 07:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks