In: Computer Science
import java.util.Scanner; class Comparisons { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter first string: "); String s1 = in.nextLine(); System.out.print("Enter second string: "); String s2 = in.nextLine(); System.out.print("Enter third string: "); String s3 = in.nextLine(); System.out.println("Largest string is " + Compare3.largest(s1, s2, s3)); System.out.print("Enter first integer: "); Integer n1 = in.nextInt(); System.out.print("Enter second integer: "); Integer n2 = in.nextInt(); System.out.print("Enter third integer: "); Integer n3 = in.nextInt(); System.out.println("Largest integer is " + Compare3.largest(n1, n2, n3)); } } class Compare3 { public static <T extends Comparable<T>> T largest(T t1, T t2, T t3) { T largest = t1; if(t2.compareTo(largest) > 0) { largest = t2; } if(t3.compareTo(largest) > 0) { largest = t3; } return largest; } }