How do I randomly select a string from an array in swift?

The static method atLongLast takes an array a of non-empty Strings and returns a String containing just the la?

  • The static method atLongLast takes an array a of non-empty Strings and returns a String containing just the last character of the longest String in a. (If there are more than one equally longest Strings in a, use the one with the smallest index in a. If a has no elements, return the empty String "".) For example: atLongLast( { "quite", "a", "short", "array" } ) has the value "e", and atLongLast( { "has", "one", "humongously", "long", "string" } ) has the value "y". Which of the following are suitable definitions for atLongLast? public static String atLongLast( String[] a ) { if ( a.length == 0 ) return ""; int maxIdx = 0; for ( int i = 1 ; i < a.length ; i++ ) { if ( a[ maxIdx ].length() < a[ i ].length() ) maxIdx = i; } return a[ maxIdx ].substring( a[ maxIdx ].length() - 1 ); } public static String atLongLast( String[] a ) { String s = ""; for ( int i = 0 ; i < a.length ; i++ ) { if ( s.length() < a[ i ].length() ) s = a[ i ]; } if ( s.equals( "" ) ) return ""; else return s.substring( s.length() - 1 ); } public static String atLongLast( String[] a ) { String s = ""; int maxIdx = 0; for ( int i = 1 ; i < a.length ; i++ ) { if ( a[ maxIdx ].length() < a[ i ].length() ) { s = a[ i ].substring( a[ i ].length() - 1 ); maxIdx = i; } } return s; } A I only B II only C I and II only D I and III only E I, II, and III I put D and I got it wrong, can someone please explain this to me and what the right answer is? Thank you!!

  • Answer:

    sry cant get u

Emmy at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.