ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2009 ICSE Computer Science Paper



Share with a Friend

Solved 2009 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Function Overloading - Number Calculation Program - ICSE 2009 Computer Science

Design a class to overload a function num_calc() as follows:
a) void num_calc(int num, char ch) - with one integer argument and one character argument computes the square of integer argument if choice ch is ‘s’ otherwise finds its cube.
b) void num_calc(int a, int b, char ch) - with two integer arguments and one character argument, computes the product of integer arguments if ch is ‘p’ else adds the integers.
c) void num_calc(String s1, String s2) - with two string arguments, which prints whether the strings are equal or not.

class Overload{ public static void numCalc(int num, char ch){ int result = 0; if(ch == 's' || ch == 'S'){ result = num * num; System.out.println("Square: " + result); } else{ result = num * num * num; System.out.println("Cube: " + result); } } public static void numCalc(int a, int b, char ch){ int result = 0; if(ch == 'p' || ch == 'P'){ result = a * b; System.out.println("Product: " + result); } else{ result = a + b; System.out.println("Sum: " + result); } } public static void numCalc(String s1, String s2){ if(s1.equals(s2)) System.out.println("Equal"); else System.out.println("Unequal"); } }

Output