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;
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.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.
0 comments:
Post a Comment