Define a method extractString() that takes in input an arrayof String. This meth
ID: 3611139 • Letter: D
Question
Define a method extractString() that takes in input an arrayof String. This method prints the first element of the array andreturns the last. Use the format of your choice for printing thefirst element.In the main() method, define an array of String and initialize itwith the following values: "This", "is", "my", "sentence".
In the main() method call method extractString() with the arraydeifned above and print the returned result on the terminal window.Use the format of your choice the print the returned result.
In the main() method, call method extractString() from the main()method with an array of your choice having a different length thanthe array above. As above, print the returned result on theterminal window.
Give reasonable comments in your code, that will show yourunderstanding of your code
Explanation / Answer
please rate - thanks import java.util.*; public class untitled { public static void main(String[] args) {String data[]={"This","is","my","sentence"}; String question[]={"Why","all","this","work","today"}; String last; last=extractString(data); System.out.println("The last element in the datastring is: "+last); last=extractString(question); System.out.println("The last element in the question stringis: "+last); } public static String extractString(String data[]) {System.out.println("The first element in the string is:"+data[0]); return data[data.length-1]; } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.