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:: 

3 comments:

Featured post

Program to find Volume of given box in java

class volume { public static void main (String args []) { int l=5,b=6,h=10; int volume; volume=l*b*h; System.out.println (" vol...