On Apr 20, 4:50 am, thufir <hawat.thu...@[EMAIL PROTECTED]
> wrote:
> For lab2 athttp://members.shaw.ca/Java2611/I
need to load data (which
> should be an array of Strings) from DATA -- that's not the assignment,
> but it's a requirement that the data is loaded in this particular
> fa****on. It's supposed to not even really be a problem, because we're
> supposed to (from my notes):
>
> hard code the data in the program,
> private final String[] GUEST_DATA = {...}
>
> use the constructor
>
> Guest guest1 = new Guest(GUEST_DATA[0]); // will grab row 0
>
> At the moment, I'd be happy to print out DATA, but I want to be able to
> iterate through DATA, assigning one row at a time to the data array,
> basically doing what's above.
>
> Yes, I'll be reviewing arrays, and it sounds straightforward, but I
don't
> see why the output is hexadecimal (the object's memory address?).
>
> Any "pointers" would be appreciated:
>
> thufir@[EMAIL PROTECTED]
javac ArrayOfStrings.java
> thufir@[EMAIL PROTECTED]
java ArrayOfStrings
> [[Ljava.lang.String;@[EMAIL PROTECTED]
> [[Ljava.lang.String;@[EMAIL PROTECTED]
> thufir@[EMAIL PROTECTED]
cat ArrayOfStrings.java
> public class ArrayOfStrings
> {
>
> public static String[] data;
>
> private final static String[][] DATA = {
> {"00", "01", "02", "03"},
> {"10", "11", "12", "13"},
> {"20", "21", "22", "23"},};
>
> public static void loadData() {
> for (int i=0; i<2; i++) {
> data = DATA[0];
> System.out.println(DATA);
> }
> }
>
> public static void main (String[] args) {
> loadData();
> }}
>
> thufir@[EMAIL PROTECTED]
>
> thanks,
>
> Thufir
if only i knew a good mentat joke . . .
you are getting memory pointers from the run because you only have one
for loop and you are walking through a 2-d array. the output is
basically DATA[0], DATA[1]. to walk through a two dimensional array,
you need nested for loops. try this:
public class ArrayOfStrings34
{
public static String data;
private final static String[][] DATA = {
{"00", "01", "02", "03"},
{"10", "11", "12", "13"},
{"20", "21", "22", "23"},};
public static void loadData() {
for (int i=0; i<DATA.length; i++) {
for (int j = 0; j < DATA[0].length; j++) {
System.out.println(DATA[i][j]);
}
}
}
public static void main (String[] args) {
loadData();
}
}


|