Friday, May 31, 2013

Multiplication of Numbers


SOURCE CODE

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

OUTPUT

Multiplication is : 108




NOTE:-

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

                System.out.println("Multiplication is : "+(a*b));
If you want to use above single line then you don't have to declare the third variable i.e. c.
You can multiply multiple numbers at a time.

0 comments:

Post a Comment

    Translate

    Protected by Copyscape