+ 2
can anybody help me out with this?
if (a.length() > b.length()) { System.out.println(a); } else if (b.length() > a.length()) { System.out.println(b); } else { System.out.println(a + b); }
5 Antworten
+ 2
lenght() is a method which return the length of something...like lenght of a string.
So first if check if 'a' is longer than 'b'. In this case it print 'a' value using System.out.println()
If 'a' is not longer than 'b', second if check if 'b' is longer than 'a'. In this case it print 'b' value using System.out.println().
If 'b' is not longer than 'a' and 'a' is not longer than 'b'...that means they are equal...will be printed their sum.
This is how "if - elseif - else" works: when none of conditions inserted in the various if/elseif is true, statements present in the last else block will be esecuted.
+ 2
If a is longer than b print a, if b is longer print b. If them are equal print a + b
+ 2
can u explain a title bit more please?
+ 1
Whichever has more elements, it will be printed.
If equal no of elements, print both
+ 1
guys I really appreciated