Asked by Nina
Hi,
I'm trying to figure out how to implement toString() methods into the JavaTest and H2ClassB classes so that the output would be 4 3 7 5 99 3:
import java.util.ArrayList;
public class JavaTest {
ArrayList <JavaTest> list = new ArrayList <JavaTest> ();
public static void main (String args []) {
JavaTest y = new JavaTest ();
int [] v = {4, 3, 7, 5, 99, 3};
for (int m: v)
y.list.add (new H2ClassB (m));
System.out.println (y);
} // end main
public String toString() { //This is where I thought
return v[1], v[2],..etc. //to put the method but I
} //don't think it's correct
} // end class JavaTest
class H2ClassB {
int x;
H2ClassB (int a) { x = a;}
} // end H2ClassB
Thanks.
I'm trying to figure out how to implement toString() methods into the JavaTest and H2ClassB classes so that the output would be 4 3 7 5 99 3:
import java.util.ArrayList;
public class JavaTest {
ArrayList <JavaTest> list = new ArrayList <JavaTest> ();
public static void main (String args []) {
JavaTest y = new JavaTest ();
int [] v = {4, 3, 7, 5, 99, 3};
for (int m: v)
y.list.add (new H2ClassB (m));
System.out.println (y);
} // end main
public String toString() { //This is where I thought
return v[1], v[2],..etc. //to put the method but I
} //don't think it's correct
} // end class JavaTest
class H2ClassB {
int x;
H2ClassB (int a) { x = a;}
} // end H2ClassB
Thanks.
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.