- Method max that has two string parameters and returns the larger of the two using String.length()
- Method max that has two string parameters and returns the larger of the two using conditional operator.
Method max that has two string parameters and returns the larger of the two using String.length()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public class StringComparision { public String maxString(String s1, String s2){ if(s1.length()>s2.length()){ return s1; } else{ return s2; } } public static void main(String args[]) { String s1="Hello kaise ho ji"; String s2="How are you"; StringComparision sc=new StringComparision(); String result=sc.maxString(s1,s2); System.out.println("Largest String is: "+result); } } |
1 | Largest String is: Hello kaise ho ji |
Method max that has two string parameters and returns the larger of the two using conditional operator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public class StringComparision { public String maxString(String s1, String s2){ return (s1.length()>s2.length())? s1:s2; } public static void main(String args[]) { String s1="Hello kaise ho ji"; String s2="How are you"; StringComparision sc=new StringComparision(); String result=sc.maxString(s1,s2); System.out.println("Largest String is: "+result); } } |
I forget this. Really very simple solution
1 | Largest String is: Hello kaise ho ji |