Java print arraylist numbered -
i have this
public string tostring() { return "a " + year + " " + make + " " + model + " vin# of " + vin + " , mileage of " + miles; }
and this:
arraylist<auto> autos = new arraylist<auto>();
and this:
public static void loadnewdata(arraylist<auto> a, arraylist<customer> c) { a.add(new auto(2009,"ford" , "mustang","abc123", 1256.54)); a.add(new auto(2010,"chevy","camero","qwi459", 33.98)); a.add(new auto(1970,"pink","cadillac","950akh", 212874.51)); a.add(new auto(2007,"lotus","elise mkii","1a2d3f", 12859.90)); c.add(new customer( "brett farve",false)); c.add(new customer( "bruce springsteen",true)); c.add(new customer( "mickey mouse", true)); c.add(new customer( "peyton manning", true)); c.add(new customer( "donald duck", true)); }
i join , print:
system.out.println(autos.tostring());
but comes out this:
[a 2009 ford mustang vin# of abc123 , mileage of 1256.54, 2010 chevy camero vin# of qwi459 , mileage of 33.98, 1970 pink cadillac vin# of 950akh , mileage of 212874.51, 2007 lotus elise mkii vin# of 1a2d3f , mileage of 12859.9]
how can make print come out this:
- a 2009 ford mustang vin# of abc123 , mileage of 1256.54
- a 2010 chevy camero vin# of qwi459 , mileage of 33.98
- a 1970 pink cadillac vin# of 950akh , mileage of 212874.51
- a 2007 lotus elise mkii vin# of 1a2d3f , mileage of 12859.9
loop on list , system.out.println
each entry. this:
for (int = 0; < autos.size(); i++) { system.out.println((i + 1) + ". " + autos.get(i)); }
Comments
Post a Comment