DCIT25 Activity
DCIT25 Activity
Lirio
BSCS 2B
1.Write a java program that appends a specified color to the end of the list of colors. The output should
look like this;
Colors: [Red, Green, Black, White, Pink, Yellow]
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.Iterator;
while (iterator.hasNext()) {
String color = iterator.next();
System.out.println(color);
}
}
}
3. Write a Java program that inserts elements into the list of flowers at the first and in last position. The
output should look like this;
Original list of flowers: [Daisy, Marigold, Rose]
Finalized list of flowers: [Carnation, Daisy, Marigold, Rose, Sunflower]
import java.util.LinkedList;
flowers.addFirst("Carnation");
flowers.addLast("Sunflower");
import java.util.LinkedList;
import java.util.Iterator;
Iterator<Integer> it = numbers.iterator();
while (it.hasNext()) {
if (it.next() % 2 != 0) {
it.remove();
}
}
import java.util.LinkedList;
if (students.contains(findStudent)) {
System.out.println("We had " + findStudent + " on the list.");
} else {
System.out.println("We can't find " + findStudent + " on the
list.");
}
}
}
Changed output: List of Names: [Anna, Brice, Mary, Penelope, Rose]
We cant find Danny on the list.
import java.util.LinkedList;
if (students.contains(findStudent)) {
System.out.println("We had " + findStudent + " on the list.");
} else {
System.out.println("We can't find " + findStudent + " on the list.");
}
}
}