Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Arithmetic Operators 
 

Arithmetic Operators are used to perform some mathematical operations like addition, subtraction, multiplication, division, and modulo (or remainder).

 

Arithmetic Operators

                         

Arithmetic Operators are used to perform some mathematical operations like addition, subtraction, multiplication, division, and modulo (or remainder). These are generally performed on an expression or operands. The symbols of arithmetic operators are given in a table:

Symbol Name of the Operator Example
 + Additive Operator   n =  n + 1;
 - Subtraction Operator  n =  n - 1;
 * Multiplication Operator   n =  n * 1;
 / Division Operator  n = n / 1;
 % Remainder Operator  n = n % 1;

The "+" operator can also be used to concatenate (to join) the two strings together. For example:

String str1 = "Concatenation of the first";
String str2 = "and second String";
String result = str1 + str2;

 The variable "result" now contains a string "Concatenation of the first and second String".

Lets have one more example implementing all arithmetic operators:

class ArithmeticDemo{
  public static void main(String[] args) {
    int x = 4;
    int y = 6;
    int z = 10;
    int rs = 0;

    rs = x + y;
    System.out.println("The addition of (x+y):"+ rs);

    rs  = y - x;
    System.out.println("The subtraction of (y-x):"+ rs);

    rs = x * y;
    System.out.println("The multiplication of (x*y):"+ rs);

    rs = y / x;
    System.out.println("The division of (y/x):"+ rs);

    rs = z % y;
    System.out.println("
The remainder of (z%x):"+ rs);

    rs = x + (y * (z/x));
    System.out.println("The result is now :"+ rs);
  }
}

Output of the Program:

C:\nisha>javac ArithmeticDemo.java

C:\nisha>java ArithmeticDemo
The addition of (x + y): 10
The subtraction of (y - x): 2
The multiplication of (x * y): 24
The division of (y / x): 1
The remainder of (z % x): 4
The result is now : 16

Download this program

                         

» View all related tutorials
Related Tags: c class static io classes instance with member delegation sse ci explicit e it ls can li use ce in

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.