Friday, May 31, 2013

Subtraction of Numbers


SOURCE CODE

class Subtraction {
public static void main(String args[]) { // start of main() method.
int a=10, b=14, c;  // initializing a & b of type integer.
c = a - b; //subtracting b from a using "-" operator and storing in c.
System.out.println("Subtraction is : "+c);  // printing result
} // end of main() method.
} // end of class.


OUTPUT

Subtraction is : -4




NOTE:-

   Instead of using
                c = a - b;
              System.out.println("Subtraction is : "+c);
you can use following single line of code

                System.out.println("Subtraction is : "+(a-b));
If you want to use above single line instead of those two then you don't have to declare the third variable i.e. c.


0 comments:

Post a Comment

    Translate

    Protected by Copyscape