Java program – Integer multiplication and division

by Nideesh C on April 28, 2011 · 0 comments

in Java Programming




public class IntOps { 

    public static void main(String[] args) {
        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[1]);
        int sum  = a + b;
        int prod = a * b;
        int quot = a / b;
        int rem  = a % b;

        System.out.println(a + " + " + b + " = " + sum);
        System.out.println(a + " * " + b + " = " + prod);
        System.out.println(a + " / " + b + " = " + quot);
        System.out.println(a + " % " + b + " = " + rem);
        System.out.println(a + " = " + quot + " * " + b + " + " + rem);
    }
}


/*************************************************************************
 *  Execution:    java IntOps a b
 *
 *  Illustrates the integer operations a * b, a / b, and a % b.
 *
 *  % java IntOps 1234 99
 *  1234 + 99 = 1333
 *  1234 * 99 = 122166
 *  1234 / 99 = 12
 *  1234 % 99 = 46
 *  1234 = 12 * 99 + 46
 *
 *  % java IntOps 10 -3
 *  10 + -3 = 7
 *  10 * -3 = -30
 *  10 / -3 = -3
 *  10 % -3 = 1
 *  10 = -3 * -3 + 1
 *
 *************************************************************************/



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Java program – String concatenation example
  2. Sample – Program to enter an integer and output the cube of that integer.
  3. C program to check whether a given integer is odd or even
  4. C program to simulate a simple calculator to perform arithmetic operations like addition, subtraction,multiplication and division only on integers
  5. Sample – Program to enter an integer and output its 15 multiples.

Leave a Comment

Previous post:

Next post: