This is a Java program that compares the lengths of two input strings and outputs the one with the maximum length.
import java.util.Scanner; class Maximum_String { public static void main(String args[]) { Scanner input = new Scanner(System.in); System.out.print("Enter the String 1 :"); String str1 = input.nextLine(); System.out.print("Enter the String 2 :"); String str2 = input.nextLine(); int len1 = str1.length(); int len2 = str2.length(); if(len1>len2) System.out.println(str1+" is Maximum String.."); else if(len2>len1) System.out.println(str2+" is Maximum String.."); else System.out.println(str1+" or "+str2+" Both are Same Length"); } }
Enter the String 1 :Apple Enter the String 2 :Banana Banana is Maximum String..
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions