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));
}
}

No comments:

Post a Comment

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