ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2011 ICSE Computer Science Paper



Share with a Friend

Solved 2011 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Function Overloading - Compare Integers, Characters, Strings Program - ICSE 2011 Computer Science

Design a class to overload a function compare() as follows:
(a) void compare(int, int): to compare two integer values and print the greater of the two integers.
(b) void compare(char, char): to compare the numeric values of two characters and print the character with higher numeric value.
(c) void compare(String, String): to compare the length of the two strings and print the longer of the two.

class Overload{ public static void compare(int a, int b){ if(a > b) System.out.println(a); else System.out.println(b); } public static void compare(char a, char b){ if(a > b) System.out.println(a); else System.out.println(b); } public static void compare(String a, String b){ if(a.length() > b.length()) System.out.println(a); else System.out.println(b); } }

Output