about | help | code help+videos | done | prefs |
public String whichIsLonger(String str1, String str2)
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) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 4
Copyright Nick Parlante 2017 - privacy