Pages

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: