Hibernate Tutorial

(Brent) #1

TUTORIALS POINT


Example


The following simple example program demonstrates the arithmetic operators. Copy and paste the following Java
program in Test.java file and compile and run this program:


public class Test{

public static void main(String args[]){
int a = 10 ;
int b = 20 ;
int c = 25 ;
int d = 25 ;
System.out.println("a + b = "+(a + b));
System.out.println("a - b = "+(a - b));
System.out.println("a * b = "+(a * b));
System.out.println("b / a = "+(b / a));
System.out.println("b % a = "+(b % a));
System.out.println("c % a = "+(c % a));
System.out.println("a++ = "+(a++));
System.out.println("b-- = "+(a--));
// Check the difference in d++ and ++d
System.out.println("d++ = "+(d++));
System.out.println("++d = "+(++d));
}
}

This would produce the following result:


a + b = 30
a - b =- 10
a * b = 200
b / a = 2
b % a = 0
c % a = 5
a++= 10
b--= 11
d++= 25
++d = 27

The Relational Operators:


There are following relational operators supported by Java language:


Assume variable A holds 10 and variable B holds 20, then:


Operator Description Example

==


Checks if the values of two operands are equal or not, if yes then
condition becomes true.
(A == B) is not true.

!=


Checks if the values of two operands are equal or not, if values are not
equal then condition becomes true.
(A != B) is true.

>


Checks if the value of left operand is greater than the value of right
operand, if yes then condition becomes true.
(A > B) is not true.

<


Checks if the value of left operand is less than the value of right
operand, if yes then condition becomes true.
(A < B) is true.

>=


Checks if the value of left operand is greater than or equal to the value
of right operand, if yes then condition becomes true.

(A >= B) is not true.
Free download pdf