4 Replies - 2044 Views - Last Post: 31 October 2010 - 12:34 AM Rate Topic: -----

#1 da_browns91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 18-February 10

Entire Array Display

Posted 30 October 2010 - 10:55 PM

public void displayList()
    {
        for(int a = 0; a < list.length; a++)
        {
            System.out.println(list[a]);
        }
        System.out.println("Sum=" + listSum + ", Average=" + listAverage);
    }



I have been at this for hours, and it has been giving me a headache. What I am trying to is display the entire array on the same line. I am sure it is something small just as it usually is.

When it comes out, it looks like

Quote

1.0
2.0
3.0
Sum=6.0, Average=2.0


What I am trying to do is make it look like

Quote

1.0,2.0,3.0
Sum=6.0, Average=2.0


Is This A Good Question/Topic? 0
  • +

Replies To: Entire Array Display

#2 Crunch  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: Entire Array Display

Posted 30 October 2010 - 10:58 PM

 System.out.print(list[a] + ",");



Should work
Was This Post Helpful? 1
  • +
  • -

#3 da_browns91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 18-February 10

Re: Entire Array Display

Posted 30 October 2010 - 11:11 PM

View PostCrunch, on 30 October 2010 - 09:58 PM, said:

 System.out.print(list[a] + ",");



Should work



That does not work, it comes out looking like

Quote

1.0,
2.0,
3.0,
Sum=6.0, Average=2.0

Was This Post Helpful? 0
  • +
  • -

#4 Handler  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 199
  • Joined: 01-April 10

Re: Entire Array Display

Posted 31 October 2010 - 12:28 AM

Change the System.out.println(); to System.out.print() and then put an empty println after the for to end that line

ps: println prints a line print appends it to the same line and not a new line
Was This Post Helpful? 1
  • +
  • -

#5 da_browns91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 18-February 10

Re: Entire Array Display

Posted 31 October 2010 - 12:34 AM

See, I knew it was something small, thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1