0% found this document useful (0 votes)
2 views5 pages

Activity 2 Java

The document contains Java code snippets for two situations. The first situation demonstrates converting an ArrayList of first names to a String array, while the second situation attempts to find a pattern in a given text. However, the second situation's code contains several errors that would prevent it from compiling successfully.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Activity 2 Java

The document contains Java code snippets for two situations. The first situation demonstrates converting an ArrayList of first names to a String array, while the second situation attempts to find a pattern in a given text. However, the second situation's code contains several errors that would prevent it from compiling successfully.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Activity 2

Paule, Angeliejoy S.

BSIT 2-B

Situation 1

Code:

import [Link];

import [Link];

public class ArrayListToStringArray{

public static void main(String args[]) {

ArrayList < String > FirstNames = new ArrayList < String > ();

[Link]("Carl");

[Link]("Andrea");

[Link]("Chloe");

[Link]("Angeliejoy");

[Link]("Justine");

ArrayList < String > LastNames = new ArrayList < String > ();

[Link]("Montefalco");

[Link]("Stroam");

[Link]("Vasquez");

[Link]("Paule");

[Link]("Zapanta");
Object[] objDays = [Link]();

String[] strDays = [Link](objDays, [Link], String[].class);

[Link]("ArrayList converted to String array");

for (int i = 0; i < [Link]; i++) {

[Link](strNames[i]);

Output:
Situation 2

public class Situation2 {

public static void main(String[] args){

String text ="Angeliejoy";

String pattern = "Joy";

int tlen = [Link]();

int plen =[Link]();

int count = 0;

char t.p;

for (int i=0; i <= tlen-plen; i=++) {

t = [Link](i);

p = [Link](0);

if (t==p) {

count++;
for(int j= i+1,k=1; k < plen; j++, k++) {

t = [Link](Angeliejoy);

p = [Link](Joy);

if (Angeliejoy==Joy)

count++;

if (count == plen)

[Link]("Pattern Found!"");

else

[Link]("Not Found!"");

}
Output:

You might also like