Task:
search "name word " from array of two multiple line and pass it to the function named "home" and print the number .
code here:
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void home(String U) {
// printing the data along with index position
System.out.println(U);
}
public static void main(String args[]) {
String one = "name";
//adding multiple line of string in array
ArrayList<String> obj1 = new ArrayList<>();
obj1.add("hey your name just come before your work in java");
obj1.add("The name program will help you to extract single word from the sentence");
for (String obj8 : obj1) {
if (obj8.contains(one)) {
int two = obj8.indexOf(one);
System.out.println(two);
String u = obj8.substring(two, two + (one.length()));
//calling home fuction in main class
home(u);
}
}
}
}
1 Comments
Good
ReplyDelete