SlideShare a Scribd company logo
Hi, Please find my code:
##### Sequence.java ##############
import java.util.ArrayList;
public class Sequence {
private ArrayList values;
public Sequence(){
values= new ArrayList();
}
public void add(int n){
values.add(n);
}
// return copy of list
public ArrayList getSequence(){
ArrayList copyList = new ArrayList<>(values.size());
for (Integer x : values) {
copyList.add(x);
}
return copyList;
}
public String toString(){
return values.toString();
}
public Sequence append(Sequence other){
Sequence res = new Sequence();
for(Integer x : values)
res.add(x);
for(Integer x:other.getSequence())
res.add(x);
return res;
}
public Sequence merge(Sequence other){
int i=0, j=0;
ArrayList otherList = other.getSequence();
Sequence mergeSeq = new Sequence();
while(i otherList = other.getSequence();
Sequence mergeSeq = new Sequence();
while(i otherList.get(j)){
mergeSeq.add(otherList.get(j));
j++;
}else{ // both have same value
mergeSeq.add(values.get(i));
i++;
j++;
}
}
while(i < values.size()){
mergeSeq.add(values.get(i));
i++;
}
while(j < otherList.size()){
mergeSeq.add(otherList.get(j));
j++;
}
return mergeSeq;
}
}
############ SequenceTest.java ###############
public class SequenceTest {
public static void main(String[] args) {
Sequence s1 = new Sequence();
Sequence s2 = new Sequence();
s1.add(1);
s1.add(4);
s1.add(9);
s1.add(16);
s2.add(9);
s2.add(7);
s2.add(4);
s2.add(9);
s2.add(11);
Sequence s3 = s1.merge(s2);
System.out.println("S1: "+s1.toString());
System.out.println("S2: "+s2.toString());
System.out.println("S1+S2: "+s3.toString());
Sequence s4 = new Sequence();
s4.add(4);
s4.add(9);
s4.add(14);
s4.add(15);
s4.add(16);
s4.add(20);
s4.add(22);
Sequence s5 = s1.mergeNoDuplicates(s4);
System.out.println("S4: "+s4.toString());
System.out.println("S1+S4(no duplicate): "+s5.toString());
}
}
/*
Sample Output:
S1: [1, 4, 9, 16]
S2: [9, 7, 4, 9, 11]
S1+S2: [1, 9, 4, 7, 9, 4, 16, 9, 11]
S4: [4, 9, 14, 15, 16, 20, 22]
S1+S4(no duplicate): [1, 4, 9, 14, 15, 16, 20, 22]
*/
Solution
Hi, Please find my code:
##### Sequence.java ##############
import java.util.ArrayList;
public class Sequence {
private ArrayList values;
public Sequence(){
values= new ArrayList();
}
public void add(int n){
values.add(n);
}
// return copy of list
public ArrayList getSequence(){
ArrayList copyList = new ArrayList<>(values.size());
for (Integer x : values) {
copyList.add(x);
}
return copyList;
}
public String toString(){
return values.toString();
}
public Sequence append(Sequence other){
Sequence res = new Sequence();
for(Integer x : values)
res.add(x);
for(Integer x:other.getSequence())
res.add(x);
return res;
}
public Sequence merge(Sequence other){
int i=0, j=0;
ArrayList otherList = other.getSequence();
Sequence mergeSeq = new Sequence();
while(i otherList = other.getSequence();
Sequence mergeSeq = new Sequence();
while(i otherList.get(j)){
mergeSeq.add(otherList.get(j));
j++;
}else{ // both have same value
mergeSeq.add(values.get(i));
i++;
j++;
}
}
while(i < values.size()){
mergeSeq.add(values.get(i));
i++;
}
while(j < otherList.size()){
mergeSeq.add(otherList.get(j));
j++;
}
return mergeSeq;
}
}
############ SequenceTest.java ###############
public class SequenceTest {
public static void main(String[] args) {
Sequence s1 = new Sequence();
Sequence s2 = new Sequence();
s1.add(1);
s1.add(4);
s1.add(9);
s1.add(16);
s2.add(9);
s2.add(7);
s2.add(4);
s2.add(9);
s2.add(11);
Sequence s3 = s1.merge(s2);
System.out.println("S1: "+s1.toString());
System.out.println("S2: "+s2.toString());
System.out.println("S1+S2: "+s3.toString());
Sequence s4 = new Sequence();
s4.add(4);
s4.add(9);
s4.add(14);
s4.add(15);
s4.add(16);
s4.add(20);
s4.add(22);
Sequence s5 = s1.mergeNoDuplicates(s4);
System.out.println("S4: "+s4.toString());
System.out.println("S1+S4(no duplicate): "+s5.toString());
}
}
/*
Sample Output:
S1: [1, 4, 9, 16]
S2: [9, 7, 4, 9, 11]
S1+S2: [1, 9, 4, 7, 9, 4, 16, 9, 11]
S4: [4, 9, 14, 15, 16, 20, 22]
S1+S4(no duplicate): [1, 4, 9, 14, 15, 16, 20, 22]
*/

More Related Content

Similar to Hi, Please find my code##### Sequence.java ##############import.pdf

How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error-   Exception in thread -main- q- Exit java-lang-.pdfHow to fix this error-   Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
aarokyaaqua
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
Stewart29UReesa
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
output and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdfoutput and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdf
access2future1
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
hemanth248901
 
sumOfSquaresimport java.util.;public class Arraylistoperation.pdf
sumOfSquaresimport java.util.;public class Arraylistoperation.pdfsumOfSquaresimport java.util.;public class Arraylistoperation.pdf
sumOfSquaresimport java.util.;public class Arraylistoperation.pdf
ankit482504
 
public class EllipsoidList { private String list- private Array.pdf
public class EllipsoidList {     private String list-    private Array.pdfpublic class EllipsoidList {     private String list-    private Array.pdf
public class EllipsoidList { private String list- private Array.pdf
3rdeyesolutions
 
07 java collection
07 java collection07 java collection
07 java collection
Abhishek Khune
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
sales88
 
Given an ArrayList, write a Java method that returns a new ArrayList.pdf
Given an ArrayList, write a Java method that returns a new ArrayList.pdfGiven an ArrayList, write a Java method that returns a new ArrayList.pdf
Given an ArrayList, write a Java method that returns a new ArrayList.pdf
feelinggift
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
Stewartt0kJohnstonh
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
aryan9007
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
allystraders
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
mckellarhastings
 
2 a networkflow
2 a networkflow2 a networkflow
2 a networkflow
Aravindharamanan S
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
BTI360
 
JDK 8
JDK 8JDK 8
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
package edu-ser222-m03_02-   ---  - A binary search tree based impleme.docxpackage edu-ser222-m03_02-   ---  - A binary search tree based impleme.docx
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
farrahkur54
 
How can I add multiple names and addresses- To the following code- Tab.pdf
How can I add multiple names and addresses- To the following code- Tab.pdfHow can I add multiple names and addresses- To the following code- Tab.pdf
How can I add multiple names and addresses- To the following code- Tab.pdf
ThomasXUMParsonsx
 
practical 9.docx
practical 9.docxpractical 9.docx
practical 9.docx
nilesh405711
 

Similar to Hi, Please find my code##### Sequence.java ##############import.pdf (20)

How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error-   Exception in thread -main- q- Exit java-lang-.pdfHow to fix this error-   Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
output and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdfoutput and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdf
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
 
sumOfSquaresimport java.util.;public class Arraylistoperation.pdf
sumOfSquaresimport java.util.;public class Arraylistoperation.pdfsumOfSquaresimport java.util.;public class Arraylistoperation.pdf
sumOfSquaresimport java.util.;public class Arraylistoperation.pdf
 
public class EllipsoidList { private String list- private Array.pdf
public class EllipsoidList {     private String list-    private Array.pdfpublic class EllipsoidList {     private String list-    private Array.pdf
public class EllipsoidList { private String list- private Array.pdf
 
07 java collection
07 java collection07 java collection
07 java collection
 
can you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdfcan you add a delete button and a add button to the below program. j.pdf
can you add a delete button and a add button to the below program. j.pdf
 
Given an ArrayList, write a Java method that returns a new ArrayList.pdf
Given an ArrayList, write a Java method that returns a new ArrayList.pdfGiven an ArrayList, write a Java method that returns a new ArrayList.pdf
Given an ArrayList, write a Java method that returns a new ArrayList.pdf
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
 
2 a networkflow
2 a networkflow2 a networkflow
2 a networkflow
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
JDK 8
JDK 8JDK 8
JDK 8
 
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
package edu-ser222-m03_02-   ---  - A binary search tree based impleme.docxpackage edu-ser222-m03_02-   ---  - A binary search tree based impleme.docx
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
 
How can I add multiple names and addresses- To the following code- Tab.pdf
How can I add multiple names and addresses- To the following code- Tab.pdfHow can I add multiple names and addresses- To the following code- Tab.pdf
How can I add multiple names and addresses- To the following code- Tab.pdf
 
practical 9.docx
practical 9.docxpractical 9.docx
practical 9.docx
 

More from anandmobile

8. Reflexive. as the hormone is releases in response to an external .pdf
8. Reflexive. as the hormone is releases in response to an external .pdf8. Reflexive. as the hormone is releases in response to an external .pdf
8. Reflexive. as the hormone is releases in response to an external .pdf
anandmobile
 
3(s) + HClSolution3(s) + HCl.pdf
3(s) + HClSolution3(s) + HCl.pdf3(s) + HClSolution3(s) + HCl.pdf
3(s) + HClSolution3(s) + HCl.pdf
anandmobile
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
anandmobile
 
This is a great question. The radial velocity met.pdf
                     This is a great question. The radial velocity met.pdf                     This is a great question. The radial velocity met.pdf
This is a great question. The radial velocity met.pdf
anandmobile
 
Viruses are intracellular obligate parasites whic.pdf
                     Viruses are intracellular obligate parasites whic.pdf                     Viruses are intracellular obligate parasites whic.pdf
Viruses are intracellular obligate parasites whic.pdf
anandmobile
 
Step1 Na is a more reactive metal than Fe ; so it.pdf
                     Step1 Na is a more reactive metal than Fe ; so it.pdf                     Step1 Na is a more reactive metal than Fe ; so it.pdf
Step1 Na is a more reactive metal than Fe ; so it.pdf
anandmobile
 
Second ionization is compared to removing electro.pdf
                     Second ionization is compared to removing electro.pdf                     Second ionization is compared to removing electro.pdf
Second ionization is compared to removing electro.pdf
anandmobile
 
oxidizing reagent CuCl2 reducing reagent Fe not.pdf
                     oxidizing reagent CuCl2 reducing reagent Fe not.pdf                     oxidizing reagent CuCl2 reducing reagent Fe not.pdf
oxidizing reagent CuCl2 reducing reagent Fe not.pdf
anandmobile
 
On the following organic compounds,CH3CH2NH2 andC.pdf
                     On the following organic compounds,CH3CH2NH2 andC.pdf                     On the following organic compounds,CH3CH2NH2 andC.pdf
On the following organic compounds,CH3CH2NH2 andC.pdf
anandmobile
 
Moseley showed that there were gaps in the atomic.pdf
                     Moseley showed that there were gaps in the atomic.pdf                     Moseley showed that there were gaps in the atomic.pdf
Moseley showed that there were gaps in the atomic.pdf
anandmobile
 
Lewis Structures A structural formula in which el.pdf
                     Lewis Structures A structural formula in which el.pdf                     Lewis Structures A structural formula in which el.pdf
Lewis Structures A structural formula in which el.pdf
anandmobile
 
fluorine , oxygen , chlorine , sulphor ,phophorus.pdf
                     fluorine , oxygen , chlorine , sulphor ,phophorus.pdf                     fluorine , oxygen , chlorine , sulphor ,phophorus.pdf
fluorine , oxygen , chlorine , sulphor ,phophorus.pdf
anandmobile
 
CuS is insoluble. NaCl stays in solution. so cor.pdf
                     CuS is insoluble. NaCl stays in solution.  so cor.pdf                     CuS is insoluble. NaCl stays in solution.  so cor.pdf
CuS is insoluble. NaCl stays in solution. so cor.pdf
anandmobile
 
When you have an acidic solution like you do, (because the H+ and th.pdf
When you have an acidic solution like you do, (because the H+ and th.pdfWhen you have an acidic solution like you do, (because the H+ and th.pdf
When you have an acidic solution like you do, (because the H+ and th.pdf
anandmobile
 
Type III secretion system- Complex structure helps the bacteria to e.pdf
Type III secretion system- Complex structure helps the bacteria to e.pdfType III secretion system- Complex structure helps the bacteria to e.pdf
Type III secretion system- Complex structure helps the bacteria to e.pdf
anandmobile
 
The OECD has produced a considerable amount of analytical work addre.pdf
The OECD has produced a considerable amount of analytical work addre.pdfThe OECD has produced a considerable amount of analytical work addre.pdf
The OECD has produced a considerable amount of analytical work addre.pdf
anandmobile
 
Q2. RAM holds the running configuration.Q4. The startup configurat.pdf
Q2. RAM holds the running configuration.Q4. The startup configurat.pdfQ2. RAM holds the running configuration.Q4. The startup configurat.pdf
Q2. RAM holds the running configuration.Q4. The startup configurat.pdf
anandmobile
 
AnswerIn population 1, only homozygous dominant population is pre.pdf
AnswerIn population 1, only homozygous dominant population is pre.pdfAnswerIn population 1, only homozygous dominant population is pre.pdf
AnswerIn population 1, only homozygous dominant population is pre.pdf
anandmobile
 
P=VI=(10)(2)=20W absorbed+ve power means absorbed -ve power means .pdf
P=VI=(10)(2)=20W absorbed+ve power means absorbed -ve power means .pdfP=VI=(10)(2)=20W absorbed+ve power means absorbed -ve power means .pdf
P=VI=(10)(2)=20W absorbed+ve power means absorbed -ve power means .pdf
anandmobile
 
Option D is the answerSolutionOption D is the answer.pdf
Option D is the answerSolutionOption D is the answer.pdfOption D is the answerSolutionOption D is the answer.pdf
Option D is the answerSolutionOption D is the answer.pdf
anandmobile
 

More from anandmobile (20)

8. Reflexive. as the hormone is releases in response to an external .pdf
8. Reflexive. as the hormone is releases in response to an external .pdf8. Reflexive. as the hormone is releases in response to an external .pdf
8. Reflexive. as the hormone is releases in response to an external .pdf
 
3(s) + HClSolution3(s) + HCl.pdf
3(s) + HClSolution3(s) + HCl.pdf3(s) + HClSolution3(s) + HCl.pdf
3(s) + HClSolution3(s) + HCl.pdf
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
 
This is a great question. The radial velocity met.pdf
                     This is a great question. The radial velocity met.pdf                     This is a great question. The radial velocity met.pdf
This is a great question. The radial velocity met.pdf
 
Viruses are intracellular obligate parasites whic.pdf
                     Viruses are intracellular obligate parasites whic.pdf                     Viruses are intracellular obligate parasites whic.pdf
Viruses are intracellular obligate parasites whic.pdf
 
Step1 Na is a more reactive metal than Fe ; so it.pdf
                     Step1 Na is a more reactive metal than Fe ; so it.pdf                     Step1 Na is a more reactive metal than Fe ; so it.pdf
Step1 Na is a more reactive metal than Fe ; so it.pdf
 
Second ionization is compared to removing electro.pdf
                     Second ionization is compared to removing electro.pdf                     Second ionization is compared to removing electro.pdf
Second ionization is compared to removing electro.pdf
 
oxidizing reagent CuCl2 reducing reagent Fe not.pdf
                     oxidizing reagent CuCl2 reducing reagent Fe not.pdf                     oxidizing reagent CuCl2 reducing reagent Fe not.pdf
oxidizing reagent CuCl2 reducing reagent Fe not.pdf
 
On the following organic compounds,CH3CH2NH2 andC.pdf
                     On the following organic compounds,CH3CH2NH2 andC.pdf                     On the following organic compounds,CH3CH2NH2 andC.pdf
On the following organic compounds,CH3CH2NH2 andC.pdf
 
Moseley showed that there were gaps in the atomic.pdf
                     Moseley showed that there were gaps in the atomic.pdf                     Moseley showed that there were gaps in the atomic.pdf
Moseley showed that there were gaps in the atomic.pdf
 
Lewis Structures A structural formula in which el.pdf
                     Lewis Structures A structural formula in which el.pdf                     Lewis Structures A structural formula in which el.pdf
Lewis Structures A structural formula in which el.pdf
 
fluorine , oxygen , chlorine , sulphor ,phophorus.pdf
                     fluorine , oxygen , chlorine , sulphor ,phophorus.pdf                     fluorine , oxygen , chlorine , sulphor ,phophorus.pdf
fluorine , oxygen , chlorine , sulphor ,phophorus.pdf
 
CuS is insoluble. NaCl stays in solution. so cor.pdf
                     CuS is insoluble. NaCl stays in solution.  so cor.pdf                     CuS is insoluble. NaCl stays in solution.  so cor.pdf
CuS is insoluble. NaCl stays in solution. so cor.pdf
 
When you have an acidic solution like you do, (because the H+ and th.pdf
When you have an acidic solution like you do, (because the H+ and th.pdfWhen you have an acidic solution like you do, (because the H+ and th.pdf
When you have an acidic solution like you do, (because the H+ and th.pdf
 
Type III secretion system- Complex structure helps the bacteria to e.pdf
Type III secretion system- Complex structure helps the bacteria to e.pdfType III secretion system- Complex structure helps the bacteria to e.pdf
Type III secretion system- Complex structure helps the bacteria to e.pdf
 
The OECD has produced a considerable amount of analytical work addre.pdf
The OECD has produced a considerable amount of analytical work addre.pdfThe OECD has produced a considerable amount of analytical work addre.pdf
The OECD has produced a considerable amount of analytical work addre.pdf
 
Q2. RAM holds the running configuration.Q4. The startup configurat.pdf
Q2. RAM holds the running configuration.Q4. The startup configurat.pdfQ2. RAM holds the running configuration.Q4. The startup configurat.pdf
Q2. RAM holds the running configuration.Q4. The startup configurat.pdf
 
AnswerIn population 1, only homozygous dominant population is pre.pdf
AnswerIn population 1, only homozygous dominant population is pre.pdfAnswerIn population 1, only homozygous dominant population is pre.pdf
AnswerIn population 1, only homozygous dominant population is pre.pdf
 
P=VI=(10)(2)=20W absorbed+ve power means absorbed -ve power means .pdf
P=VI=(10)(2)=20W absorbed+ve power means absorbed -ve power means .pdfP=VI=(10)(2)=20W absorbed+ve power means absorbed -ve power means .pdf
P=VI=(10)(2)=20W absorbed+ve power means absorbed -ve power means .pdf
 
Option D is the answerSolutionOption D is the answer.pdf
Option D is the answerSolutionOption D is the answer.pdfOption D is the answerSolutionOption D is the answer.pdf
Option D is the answerSolutionOption D is the answer.pdf
 

Recently uploaded

คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 

Recently uploaded (20)

คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 

Hi, Please find my code##### Sequence.java ##############import.pdf

  • 1. Hi, Please find my code: ##### Sequence.java ############## import java.util.ArrayList; public class Sequence { private ArrayList values; public Sequence(){ values= new ArrayList(); } public void add(int n){ values.add(n); } // return copy of list public ArrayList getSequence(){ ArrayList copyList = new ArrayList<>(values.size()); for (Integer x : values) { copyList.add(x); } return copyList; } public String toString(){ return values.toString(); } public Sequence append(Sequence other){ Sequence res = new Sequence(); for(Integer x : values) res.add(x); for(Integer x:other.getSequence()) res.add(x); return res; } public Sequence merge(Sequence other){ int i=0, j=0; ArrayList otherList = other.getSequence(); Sequence mergeSeq = new Sequence(); while(i otherList = other.getSequence();
  • 2. Sequence mergeSeq = new Sequence(); while(i otherList.get(j)){ mergeSeq.add(otherList.get(j)); j++; }else{ // both have same value mergeSeq.add(values.get(i)); i++; j++; } } while(i < values.size()){ mergeSeq.add(values.get(i)); i++; } while(j < otherList.size()){ mergeSeq.add(otherList.get(j)); j++; } return mergeSeq; } } ############ SequenceTest.java ############### public class SequenceTest { public static void main(String[] args) { Sequence s1 = new Sequence(); Sequence s2 = new Sequence(); s1.add(1); s1.add(4); s1.add(9); s1.add(16);
  • 3. s2.add(9); s2.add(7); s2.add(4); s2.add(9); s2.add(11); Sequence s3 = s1.merge(s2); System.out.println("S1: "+s1.toString()); System.out.println("S2: "+s2.toString()); System.out.println("S1+S2: "+s3.toString()); Sequence s4 = new Sequence(); s4.add(4); s4.add(9); s4.add(14); s4.add(15); s4.add(16); s4.add(20); s4.add(22); Sequence s5 = s1.mergeNoDuplicates(s4); System.out.println("S4: "+s4.toString()); System.out.println("S1+S4(no duplicate): "+s5.toString()); } } /* Sample Output: S1: [1, 4, 9, 16] S2: [9, 7, 4, 9, 11] S1+S2: [1, 9, 4, 7, 9, 4, 16, 9, 11] S4: [4, 9, 14, 15, 16, 20, 22] S1+S4(no duplicate): [1, 4, 9, 14, 15, 16, 20, 22] */
  • 4. Solution Hi, Please find my code: ##### Sequence.java ############## import java.util.ArrayList; public class Sequence { private ArrayList values; public Sequence(){ values= new ArrayList(); } public void add(int n){ values.add(n); } // return copy of list public ArrayList getSequence(){ ArrayList copyList = new ArrayList<>(values.size()); for (Integer x : values) { copyList.add(x); } return copyList; } public String toString(){ return values.toString(); } public Sequence append(Sequence other){ Sequence res = new Sequence(); for(Integer x : values) res.add(x); for(Integer x:other.getSequence()) res.add(x); return res; } public Sequence merge(Sequence other){ int i=0, j=0; ArrayList otherList = other.getSequence();
  • 5. Sequence mergeSeq = new Sequence(); while(i otherList = other.getSequence(); Sequence mergeSeq = new Sequence(); while(i otherList.get(j)){ mergeSeq.add(otherList.get(j)); j++; }else{ // both have same value mergeSeq.add(values.get(i)); i++; j++; } } while(i < values.size()){ mergeSeq.add(values.get(i)); i++; } while(j < otherList.size()){ mergeSeq.add(otherList.get(j)); j++; } return mergeSeq; } } ############ SequenceTest.java ############### public class SequenceTest { public static void main(String[] args) { Sequence s1 = new Sequence(); Sequence s2 = new Sequence(); s1.add(1); s1.add(4); s1.add(9);
  • 6. s1.add(16); s2.add(9); s2.add(7); s2.add(4); s2.add(9); s2.add(11); Sequence s3 = s1.merge(s2); System.out.println("S1: "+s1.toString()); System.out.println("S2: "+s2.toString()); System.out.println("S1+S2: "+s3.toString()); Sequence s4 = new Sequence(); s4.add(4); s4.add(9); s4.add(14); s4.add(15); s4.add(16); s4.add(20); s4.add(22); Sequence s5 = s1.mergeNoDuplicates(s4); System.out.println("S4: "+s4.toString()); System.out.println("S1+S4(no duplicate): "+s5.toString()); } } /* Sample Output: S1: [1, 4, 9, 16] S2: [9, 7, 4, 9, 11] S1+S2: [1, 9, 4, 7, 9, 4, 16, 9, 11] S4: [4, 9, 14, 15, 16, 20, 22]
  • 7. S1+S4(no duplicate): [1, 4, 9, 14, 15, 16, 20, 22] */