Program
import java.util.*;
class Myclass {
int add(int a, int b)
{
for (int i = 1; i <= b; i++)
a++;
return a;
}
}
class Demo1
{
public static void main(String[] args)
{
Myclass m=new Myclass();
int x,y,z;
Scanner s=new Scanner(System.in);
System.out.println("Enter x value");
x=s.nextInt();
System.out.println("Enter y value");
y=s.nextInt();
z = m.add(x, y);
System.out.print("Addition is :"+z);
}
}
Output:
Enter x value: 10
Enter y value: 20
Addition is : 30
Enter x value: 12
Enter y value: 12
Addition is : 24
For latest job updates join Telegram Channel: https://t.me/sateeshm