Saturday, 9 March 2019

Program to subtract two number in Java

Here we learn how to write a program in java to subtract 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.

the program will be executed the same as the earlier addition program https://www.programmingponds.com/2019/02/program-to-add-two-number-in-java.html

class sub_num
{
public int sub (int a, int b)
{
return (a-b);
}
}
class subnum
{
public static void main (String args[])
{
int a,b;
a=40;
b=10;
sub_num subobj=new sub_num();
System.out.println("subtraction="+subobj.add(a,b));
}
}

1 comment:

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