id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

srp4379@lausd.net > whichIsLonger
prev  |  next  |  chance

public String whichIsLonger(String str1, String str2)

Given TWO strings, return the longer one.

  int len1 = str1.length();
  int len2 = str2.length();
  String longer = str1; // default, assume str1 is longer
  if (len2 > len1) { 
    longer = str2;  // if str2 is longer!
  }
  return longer;

OR

  int len1 = str1.length();
  int len2 = str2.length();
  if (len2 > len1) { 
    return str2; // if str2 is longer
  }
  return str1; // if str1 is longer


whichIsLonger("abc", "defg") → "defg"
whichIsLonger("abcd", "efg") → "abcd"
whichIsLonger("12", "123") → "123"

...Save, Compile, Run (ctrl-enter)

public String whichIsLonger(String str1, String str2) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 4

Copyright Nick Parlante 2017 - privacy