Page 108 - CTS - CSA TP - Volume 2
P. 108
COMPUTER SOFTWARE APPLICATION - CITS
Output :
Explanation:
• In this program, we define a method add that takes two integers as parameters and returns their sum.
• We declare variables x and y in the main method and assign values to them.
• We call the add method and pass x and y as arguments.
• The method performs addition on the provided integers and returns the result, which is then printed in the main
method.
Here’s another example demonstrating the concept of passing primitive data types to methods:
TASK 2: Finding the Maximum of Two Integers
public class MaximumDemo {
public static void main(String[] args) {
int a = 10;
int b = 20;
// Calling the method to find the maximum of two integers
int max = findMaximum(a, b);
System.out.println(“Maximum of “ + a + “ and “ + b + “ is: “ + max);
}
// Method to find the maximum of two integers
public static int findMaximum(int x, int y) {
return (x > y) ? x : y;
}
}
93
CITS : IT & ITES - Computer Software Application - Exercise 95