Tuesday, August 4, 2009

Operator

In Java, there are several types of service. There are arithmetic operators, customer service, service logic, and service conditions. Operator follows the various priorities that so compilernya akan know which service to run in the first some cases the service is shared in a statement.

Operator arithmetic
The following are the basic arithmetic operators that can be used to create a
Java programs:

+ : op1 + op2 Adding op2 with Op1
* : op1 * op2 op1 to op2 multiplying
/ : op1 / op2 Sharing op1 with op2
% : op1 % op2 Calculating the rest of the division of op1 with op2
- : op1 - op2 reduce op2 from op1

Here is an example program in the use of this operator-operator:

public class aritmatikaDemo
{
public static void main(String[] args)
{
//little number
int i = 37;
int j = 42;
double x = 27.475;
double y = 7.22;
System.out.println("Variable values...");
System.out.println(" i = " + i);
System.out.println(" j = " + j);
System.out.println(" x = " + x);
System.out.println(" y = " + y); //Answer number
System.out.println("Adding...");
System.out.println(" i + j = " + (i + j));
System.out.println(" x + y = " + (x + y));
//reduction in the number
System.out.println("Subtracting...");
System.out.println(" i - j = " + (i - j));
System.out.println(" x - y = " + (x - y));
//digit multiplication
System.out.println("Multiplying...");
System.out.println(" i * j = " + (i * j));
System.out.println(" x * y = " + (x * y));
//division number
System.out.println("Dividing...");
System.out.println(" i / j = " + (i / j));
System.out.println(" x / y = " + (x / y));
//calculate the modulus results from the division of
System.out.println("Computing the remainder...");
System.out.println(" i % j = " + (i % j));
System.out.println(" x % y = " + (x % y));
//type of merger
System.out.println("Mixing tipes...");
System.out.println(" j + y = " + (j + y));
System.out.println(" i * x = " + (i * x));
}
}

Below is the output of the program,

Variable values...
i = 37
j = 42
x = 27.475
y = 7.22
i + j = 79
Adding...
x + y = 34.695
Subtracting...
i - j = -5
x - y = 20.255
Multiplying...
i * j = 1554
x * y = 198.37
Dividing...
i / j = 0
x / y = 3.8054
Computing the remainder...
i % j = 37
x % y = 5.815
Mixing tipes...
j + y = 49.22
i * x = 1016.58


Operator Increment and Decrement

From the basic arithmetic operators, also consists of the Java unary increment operator (+ +)
and unary decrement operator (--). increment and decrement operators increase and reduce the value stored in the form of a variable number of value 1. For example, the statement,

count = count + 1; //count value increment with a value of 1

with the same statement,

count++;


OP++ :Adding value in the op 1; evaluate the value of op before diincrementasi / added
++OP :Adding value in the op 1; evaluate the value of op before diincrementasi / added
OP-- :Reduce the value 1 on the op; evaluate the value of op before diincrementasi / added
--OP :Reduce the value 1 on the op; evaluate the value of op before diincrementasi / added

Increment and decrement operators can be placed before or after the operand.

When used before the operand, will result in a variable or diincrement didecrement with a value of 1, and then a new value is used in the statement where he added. For example,

int i = 10,
int j = 3;
int k = 0;
k = ++j + i; //yield k = 4+10 = 14


When the increment and decrement operators are placed after the operand, the value of the variable old will be used first operated prior to the statement which he added. For example,

int i = 10,
int j = 3;
int k = 0;
k = j++ + i; //yield k = 3+10 = 13



Relations Operator

Relations operator to compare two values and determine the relationship between values it. Of the output is a boolean value that is true or false.

" > Op1> op2 op1 is greater than op2"
" > = Op1> = op2 op1 is greater than or equal to op2"
" < Op1 <= Op1 <= op2 op1 is less than or equal to op2 "
" == Op1 == op2 op1 together with op2 "
" ! = Op1! = Op2 op1 is not equal to op2 "

Here is an example program that uses the service relations,

public class RelasiDemo { public static void main(String[] args)

{ //some value int i = 37; int j = 42; int k = 42;
System.out.println("Variable values...");
System.out.println(" i = " + i);
System.out.println(" j = " + j);
System.out.println(" k = " + k); //greater than System.out.println("Greater than..."); System.out.println(" i > j = " + (i > j)); //false
System.out.println(" j > i = " + (j > i)); //true
System.out.println(" k > j = " + (k > j)); //false
//greater or equal to
System.out.println("Greater or equal to...");
System.out.println(" i >= j = " + (i >= j)); //false
System.out.println(" j >= i = " + (j >= i)); //true
System.out.println(" k >= j = " + (k >= j)); //true
//less than
System.out.println("Less than...");
System.out.println(" i < j =" ">
System.out.println(" j < i =" ">
System.out.println(" k < j =" ">
//Less than or equal to
System.out.println("Less than or equal to...");
System.out.println(" i <= j = " + (i <= j)); //true
System.out.println(" j <= i = " + (j <= i)); //false
System.out.println(" k <= j = " + (k <= j)); //true //with the same
System.out.println("with the same...");
System.out.println(" i == j = " + (i == j)); //false
System.out.println(" k == j = " + (k == j)); //true //not the same as
System.out.println("Not the same as...");
System.out.println(" i != j = " + (i != j)); //true
System.out.println(" k != j = " + (k != j)); //false
}
}



Here is the result of the output from this program:

Variable values...
i = 37
j = 42
k = 42
Greater than...
i > j = false
j > i = true
k > j = false
Greater or equal to...
i >= j = false
j >= i = true
k >= j = true
Less than...
i < j =" true">
j < i =" false">
k < j =" false">
Less than or equal to...
i <= j = true
j <= i = false
k <= j = true with the same...
i == j = false
k == j = true
Not the same as...
i != j = true
k != j = false

No comments:

Post a Comment