Computer Science, asked by dasb3557, 1 month ago

Wap to display the word cross from the string holy cross school​

Answers

Answered by anindyaadhikari13
3

\texttt{\textsf{\large{\underline{Solution}:}}}

Using Java.

public class StringOp{

   public static void main(){

       String str="holy cross school";

       String arr[]=str.split(" ");

       System.out.println(arr[1]);

   }

}

Using Python.

str="holy cross school"

arr=str.split()

print(arr[1])

\texttt{\textsf{\large{\underline{Explanation}:}}}

  • str stores the string "holy cross school". Then using split() method, all the words of the string is stored in an array. Now, word "cross" is stored at second index which is 1 (as index value starts from 1). Therefore, it is accessed by writing arr[1], hence displayed.

See the attachment for output.

Attachments:
Similar questions