Welcome to Dream.In.Code
Become a Java Expert!

Join 150,356 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,945 people online right now. Registration is fast and FREE... Join Now!




ArrayList of 10 Numbers

 
Reply to this topicStart new topic

ArrayList of 10 Numbers

peterdog
7 Feb, 2008 - 09:18 PM
Post #1

New D.I.C Head
*

Joined: 24 Oct, 2007
Posts: 4


My Contributions
CODE
import TerminalIO.KeyboardReader;  

public class ArrayListNumPV
{
  public static void main (String[] args)
  {
//ArrayList containing 0 1 2 3 4 5 6 7 8 9 10
ArrayList<Integer> list = new ArrayList<Integer>();

int length = 11;
for(int k =1; k<length; k++)
{
    total+=k;
    total++;
}
for(Integer total : list)
{
System.out.println(total);
}

int average = (total/length);
System.out.println(average);



list = list.remove(3);
list = list.remove(4);
list.add(20,25);
  }
}


Hello, i am trying to create ArrayList of 10 numbers, use a for loop. Print total , print average, add 20,25, print ArrayList (is that the for(Integer total : list)?) and remove the 3rd and 4th numbers in the list..

Its first ArrayList program for me and i am struggling, I think i have the basics down but.. ALSO ---public static void main (String[] args) i know there arent supposed to be any parameters but i dont know what to put instead. sigh thank you for the help.
User is offlineProfile CardPM
+Quote Post

Nayana
RE: ArrayList Of 10 Numbers
8 Feb, 2008 - 05:24 AM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
You don't need to go list = list.remove(x);, you can just go list.remove(x);.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:40PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month