class addition
{
public static void main(String[] args)
{
int a=12,b=13,c;
c=a+b;
System.out.println("Value of a="+a);
System.out.println("Value of b="+b);
System.out.println("Sum="+c);
}
}
O/P:-
Value of a=12
Value of b=13
Sum=25
=====================================================================
* Uning Class and Object sum of two number.
import java.util.Scanner;
class Add
{
Scanner sc=new Scanner (System.in);
int a,b;
void addition()
{
System.out.println("Enter Two Number");
a=sc.nextInt();
b=sc.nextInt();
}
void display()
{
System.out.println("Sum="+(a+b));
}
}
class Add1
{
public static void main(String[] args)
{
Add p=new Add();
p.addition();
p.display();
}
}
0 Comments