Help?

0 Laura Rosario · December 3, 2014
So I'm doing one of my assignments for my Comp Sci lab(Self teaching myself Java because my Professor is incompetent) and the assignment is asking me to do this:
Write a complete program in which main creates two Integer
arrayLists and then adds 1, 2, …, 10 to the first ArrayList,
and 21, 22, …, 30 to the second ArrayList. main should
call a method passing it the two ArrayLists. This method
should create and return a third ArrayList, each slot of
which contains the sum of the values in the corresponding
slots of the first and second ArrayLists. On return to
main, main should display the values in the third
ArrayList.

and this is the code I've programmed so far:
import java.util.ArrayList;
class lbn2
{
    public static void main(String[] args)
    {
        ArrayList<String> alpha = new ArrayList<String>();
        ArrayList<String> beta = new ArrayList<String>();
        for(int i = 1; i <= 10; i++)
        {
            alpha.add(i);
        }
        for(int i = 21; i <= 30; i++)
        {
            beta.add(i);
        }
    }
    public static ArrayList sum(ArrayList a,ArrayList b)
     {
       ArrayList<String> charlie = new ArrayList<String>();
       for(int i = 0; i < a.size();i++)
       {   
            charlie.addAll(a);
            charlie.addAll(b);
       }
      for(String temp: charlie)
      {
          System.out.println(temp);
      }
    }
}   

Although when I compile it tells me theres no suitable method found for add(int). If anyone could help me that'd be great

Post a Reply

Replies

Oldest  Newest  Rating
0 Laura Rosario · December 3, 2014
Ahh my apologies, I fixed it thank you!
  • 1

Java / Android Development

106,989 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator