Addition Subtraction (Hikizan) Multiplication Division (division)
In addition to this, there is a remainder division (modulo operation) that finds the remainder after division. The four arithmetic operations are used in exactly the same way as mathematical formulas. The only difference is that the multiplication (x) uses (*) and the division uses (/) instead of (÷).
result1 = x + y; //Addition
result2 = x - y; //Subtraction
result3 = x * y; //Multiplication
result4 = x / y; //division
result5 = x % y; //Modulo arithmetic
The above calculation is also possible with integer type such as int and floating point type.
The "+" symbol can be used not only for addition but also for concatenating character strings. If you select "abc" + "de", the output result will be "abcde".
String str = "Hello" + "Qiita" + "Mr.";
System.out.println(str);
You can concatenate variables. You can concatenate string literals and variables with "+".
String name = "Qiita";
System.out.println("Good evening" + name + "Mr.");
Also, the most important function of the string concatenation operator "+" is to concatenate strings with any type of data. When concatenating with this function, any type of data will be converted to "String type" and concatenated.
eclipse is not used this time
Operator/
├──Operator.java
Operator.java
public class Operator{
public static void main(String[] args){
int x = 6;
int y = 3;
int result1 = 0;
int result2 = 0;
int result3 = 0;
int result4 = 0;
//Operators of four arithmetic operations
result1 = x + y; //Addition
result2 = x - y; //Subtraction
result3 = x * y; //Multiplication
result4 = x / y; //division
System.out.println( result1 + "=" + x + "+"+ y);
System.out.println( result2 + "=" + x + "-"+ y);
System.out.println( result3 + "=" + x + "*"+ y);
System.out.println( result4 + "=" + x + "/"+ y);
//String concatenation
String str = "Hello" + "Qiita" + "Mr.";
System.out.println(str);
//String literals and variables"+"Connect using
String name = "Qiita";
System.out.println("Good evening" + name + "Mr.");
}
}
Recommended Posts