I want to make an application where I take a number, which is the ammount of boxes, create an array and then fill out the array with the height of boxes and then print out all the boxes in the array with their height.
public class Boxes {
static class Box {
int height;
Box(int h) {
this.height = h;
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
Box arr[] = new Box[n];
for (int i = 0; i < n; i++) {
int h = s.nextInt();
arr[i] = new Box(h);
}
System.out.println(Arrays.toString(arr));
}
}
When I enter 3 5 3 2 I want it to print out 5,3,2, but it prints out a memory address.