Tuesday, 19 February 2019

Program to add two number in Java

Here we learn how to write a program in java to add two numbers. We made two class here but you have to save your file name with the second class name because compiler starts execution on that class where main () is placed.

class add_num
{
public int add (int a, int b)
{
return (a+b);
}
}
class Addnum
{
public static void main (String args[])
{
int a,b;
a=10;
b=23;
add_num addobj=new add_num();
System.out.println("Addition="+addobj.add(a,b));
}
}

Output:: 

2 comments:

Featured post

Kalgudi Interview Round!!

Those who cleared the second round of kalgudi got an email from exceller to complete their Kalgudi Interview Round. So here we will discuss ...