1. ' + '; plus operator
' + ' in Java in addition to the function of the wig operation, there are two characters to connect the function
public class HelloWorld {
int i=33;
int j=44;
Char c1= ' a ';
Char c2= ' B ';
public static void Main (String args[])
{
HelloWorld hw=new HelloWorld ();
int N=HW.I+HW.J;
int c=hw.c2+hw.c1;
SYSTEM.OUT.PRINTLN (n);
System.out.println (c);
}
}
When you concatenate multiple characters, you can connect with multiple addition operators, but there are drawbacks to doing so.
2. '-'; subtraction operator
With the following example, you can understand:
public class Jian {
int i=44;
int j=22;
Char c1= ' h ';
Char c2= ' a ';
public static void Main (String args[])
{
Jian Hl=new jian ();
int N=HL.I-HL.J;
int c=hl.c1-hl.c2;
SYSTEM.OUT.PRINTLN (n);
System.out.println (c);
}
}
3. '/': division operator
You can do the division of integers, or you can do the division of floating-point numbers.
public class Chufa {
float i=23;
float j=11;
public static void Main (String args[])
{
Chufa hl=new Chufa ();
float N=HL.I/HL.J;
SYSTEM.OUT.PRINTLN (n);
}
}
Floating point division, the result is 2.090909
It seems to be a rounding operation when divisible.
public class Chufa {
int i=23;
int j=11;
public static void Main (String args[])
{
Chufa hl=new Chufa ();
int N=HL.I/HL.J;
SYSTEM.OUT.PRINTLN (n);
}
}
The result is 2.
4. '% ': Seek remainder operator
public class Yu {
int i=24;
int j=5;
public static void Main (String args[])
{
Yu Hl=new yu ();
int N=HL.I%HL.J;
SYSTEM.OUT.PRINTLN (n);
}
}
Integer remainder: The result is 4
Floating-point number for remainder, the divisor is 0, the result is Nan.
public class Yu {
float i=24;
float j=0;
public static void Main (String args[])
{
Yu Hl=new yu ();
float N=HL.I%HL.J;
SYSTEM.OUT.PRINTLN (n);
}
}
Result Output Nan
When the remainder is obtained, the divisor is negative and the result is positive
public class Yu {
int i=24;
int j=-5;
public static void Main (String args[])
{
Yu Hl=new yu ();
int N=HL.I%HL.J;
SYSTEM.OUT.PRINTLN (n);
}
}
Result output 4
When the remainder is obtained, the divisor is negative and the result is negative.
Package Yu;
public class Yu {
int i=-24;
int j=5;
public static void Main (String args[])
{
Yu Hl=new yu ();
int N=HL.I%HL.J;
SYSTEM.OUT.PRINTLN (n);
}
}
Result Output-4
Divisor and dividend are negative, the equivalent of dividend is negative, the result is negative
Package Yu;
public class Yu {
int i=-24;
int j=-5;
public static void Main (String args[])
{
Yu Hl=new yu ();
int N=HL.I%HL.J;
SYSTEM.OUT.PRINTLN (n);
}
}
Output-4
Java Learning Note II (Java operator)