Computer Science 1 - Dalhousie University
CSCI 1101 – Winter 2012
Laboratory Report 6
SOLUTIONS
Exercise 2: Write a program that reads words into two ArrayLists list1 and list2 and then creates a third ArrayList that contains words which are common to both list1 and list2. You may assume that the strings are entered as words separated by a space on a single line and the end is signaled by “-1” (String -1). You can use keyboard.next() to read each word.
A sample dialog is shown below:
Enter words on one line, end with -1
java c pascal ada java c++ -1
Enter words on one line, end with -1
c pascal java lisp lisp -1
[java, c, pascal, ada, java, c++]
[c, pascal, java, lisp, lisp]
Array List with common strings:
[c, pascal, java]
SOLUTION: (Core part only)
int i,j;
ArrayList result = new ArrayList();
if (list1.size() >= list2.size())
{
for(i=0;i ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- igcse computer science workbooks pdf
- igcse computer science workbook
- igcse computer science workbook answer
- igcse computer science coursebook pdf
- computer science people
- what is computer science like
- computer science revision
- igcse computer science revision notes
- college computer science project ideas
- ideas for computer science project
- computer science projects for students
- computer science final project