SOURCE CODE
class addition {
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; // adding a & b using "+" operator and storing in c.
System.out.println("Addition : "+c); // printing result
} // ending of main() method.
} // end of the class.
OUTPUT
Addition : 24
NOTE:-
Instead of using
c = a + b;
System.out.println("Addition : "+c);c = a + b;
you can use following single line of code
System.out.println("Addition : "+(a+b));
If you want to use above single line then you don't need to declare the third variable i.e. c.
0 comments:
Post a Comment