+ 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); }

2nd Oct 2017, 11:21 PM
Jman
Jman - avatar
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.
2nd Oct 2017, 11:39 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
+ 2
If a is longer than b print a, if b is longer print b. If them are equal print a + b
2nd Oct 2017, 11:25 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
+ 2
can u explain a title bit more please?
2nd Oct 2017, 11:30 PM
Jman
Jman - avatar
+ 1
Whichever has more elements, it will be printed. If equal no of elements, print both
3rd Oct 2017, 12:02 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
guys I really appreciated
6th Oct 2017, 6:14 PM
Jman
Jman - avatar