Let\'s say i have a class \"Node\" which has two initial variables: String name;
ID: 3620315 • Letter: L
Question
Let's say i have a class "Node" which has two initial variables:String name;
String number;
public Node(String naming, String numering)
{
name =naming;
number = numering;
}
Let's say i have a new class "SecondClass" which has an array called:
Node[] both = new Node[150];
Let us assume that Node[1] = ("Jason","98");
Here is the question:
If i want to print out the strings inside Node[1] , then do I do:
System.out.println(both.name , both.number) IF THIS IS WRONG THEN PLEASE CORRECT ME.
System.out.println(both.name , both.number) IF THIS IS WRONG THEN PLEASE CORRECT ME.
Explanation / Answer
You may need a second opinion but due to the fact that both is an array, you need to specify the index of the array both that you want. so it would be: System.out.println( both[1].name + ", " + both[1].number); Notes: Java starts counting from 0, so the first index of both would actually be both[0], not sure if that affects anything but worth a mention. Also, if you want the comma to appear in the output you need to concatenate as I did using + ", " + . Hope that helps.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.