skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Friday, January 6, 2012

Performing Arithmetic Opration on Two Variable in Java

Posted by Admin at 9:05 AM – 0 comments
 
Here is a Program to Perform the Arithmetic Operation between two Variable
public class IntOps { 

    public static void main(String[] args) {
         /*
 * Here we have used parstInt method to convert string to integer
 */
        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;
     
        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);
    }
}

/*****************
 * Output of Program
 * 
 *  % java IntOps 10 -3
 *  10 + -3 = 7
 *  10 * -3 = -30
 *  10 / -3 = -3
 *  10 % -3 = 1
 *  10 = -3 * -3 + 1
 *
 **********************/

Explanation of Arithmetic Operation Java Program

In this program we have two variable a and b which has command line argument value after assigning those value we have performed different operation on Variable which is afterward outputted to console using System.out.println() Method.



Labels: Arithmetic Operation , Basic Java Programs

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger