Tool version compatibility problem
Arithmetic operators
Basically ：
+ - * / %

Self increasing Self subtraction
++ --
Correct

This video is interpretive , So I hope you have read the content of this knowledge point , And after writing the corresponding code , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning

13 branch 21 second

Example 1 : Basic arithmetic operators
Example 2 : practice - Sum
Example 3 : answer - Sum
Example 4 : The length of any arithmetic unit exceeds int
Example 5 : The length of any arithmetic unit is less than int
Example 6 : % Take the mold
Example 7 : Self increasing Self subtraction
Example 8 : Self increasing The difference between before and after the subtraction operator
Example 9 : practice - Self increasing
Example 10 : answer - Self increasing
Example 11 : practice -BMI

Example 1 :

Basic arithmetic operators

top fracture

+ - * /

Basic plus Minus Take except
public class HelloWorld { public static void main(String[] args) { int i = 10; int j = 5; int a = i+j; int b = i - j; int c = i*j; int d = i /j; } }
```public class HelloWorld {
public static void main(String[] args) {
int i = 10;
int j = 5;
int a = i+j;
int b = i - j;
int c = i*j;
int d = i /j;
}
}
```
Example 2 :

practice - Sum

top fracture   Wrong posture , get half the results with double the effort ! Click to see the correct posture for the exercise
use Scanner Get two numbers from the console , Then calculate the sum of these two numbers

If you can't use Scanner, Please refer to How to use Scanner Read integers
Example 3 :

top fracture
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Account not activated , Limited functionality . Please click activate
This video is interpretive , So I hope you have read the content of this answer , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning

import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { Scanner s = new Scanner(System.in); int a = s.nextInt(); System.out.println(" The first integer ："+a); int b = s.nextInt(); System.out.println(" The second integer ："+b); int c = a+b; System.out.println(" The sum of two numbers is ：" + c); } }
```import java.util.Scanner;

public class HelloWorld {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int a = s.nextInt();
System.out.println(" The first integer ："+a);
int b = s.nextInt();
System.out.println(" The second integer ："+b);
int c = a+b;
System.out.println(" The sum of two numbers is  ：" + c);
}
}
```
Example 4 :

The length of any arithmetic unit exceeds int

top fracture
If any arithmetic unit is longer than int, Then the calculation result is calculated according to the longest length
For example
int a = 5;
long b = 6;
a+b -> The result type is long
public class HelloWorld { public static void main(String[] args) { int a = 5; long b = 6; int c = (int) (a+b); //a+b The result of the operation is long Type , So we need to cast long d = a+b; } }
```public class HelloWorld {
public static void main(String[] args) {

int a = 5;
long b = 6;
int c = (int) (a+b); //a+b The result of the operation is long Type , So we need to cast
long d = a+b;

}
}
```
Example 5 :

The length of any arithmetic unit is less than int

top fracture
If the length of any arithmetic unit does not exceed int, Then the result is calculated according to int To calculate
byte a = 1;
byte b= 2;
a+b -> int type
public class HelloWorld { public static void main(String[] args) { byte a = 1; byte b= 2; byte c = (byte) (a+b); // Although a b It's all byte type , But the result is int type , Cast required int d = a+b; } }
```public class HelloWorld {
public static void main(String[] args) {
byte a = 1;
byte b= 2;
byte c = (byte) (a+b); // Although a b It's all byte type , But the result is int type , Cast required
int d = a+b;
}
}
```
Example 6 :

% Take the mold

top fracture
% Take the remainder , Also called mold taking
5 divide 2, I 1
public class HelloWorld { public static void main(String[] args) { int i = 5; int j = 2; System.out.println(i%j); // The output is 1 } }
```public class HelloWorld {
public static void main(String[] args) {

int i = 5;
int j = 2;
System.out.println(i%j); // The output is 1
}
}
```
Example 7 :

Self increasing Self subtraction

top fracture
++
--
Add... On the original basis 1 Or reduce 1
public class HelloWorld { public static void main(String[] args) { int i = 5; i++; System.out.println(i);// The output is 6 } }
```public class HelloWorld {
public static void main(String[] args) {

int i = 5;
i++;
System.out.println(i);// The output is 6

}
}
```
Example 8 :

Self increasing The difference between before and after the subtraction operator

top fracture
With ++ take as an example
int i = 5;
i++; Take the value first , Then calculate
++i; First calculate , Take another value
public class HelloWorld { public static void main(String[] args) { int i = 5; System.out.println(i++); // Output 5 System.out.println(i); // Output 6 int j = 5; System.out.println(++j); // Output 6 System.out.println(j); // Output 6 } }
```public class HelloWorld {
public static void main(String[] args) {
int i = 5;
System.out.println(i++); // Output 5
System.out.println(i);   // Output 6

int j = 5;
System.out.println(++j); // Output 6
System.out.println(j);	 // Output 6
}
}
```
Example 9 :

practice - Self increasing

top fracture   Wrong posture , get half the results with double the effort ! Click to see the correct posture for the exercise

int i = 1;
int j = ++i + i++ + ++i + ++i + i++;

ask j What is the result of ?
notes : Don't put it in eclipse In , According to ++ Front setting After the understanding, calculate it yourself first , Then look at the answer
Example 10 :

top fracture
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Account not activated , Limited functionality . Please click activate
This video is interpretive , So I hope you have read the content of this answer , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning

public class HelloWorld { public static void main(String[] args) { int i = 1; int j = ++i + i++ + ++i + ++i + i++; //i value 2 3 4 5 6 // Value 2 2 4 5 5 System.out.println(j); } }
```public class HelloWorld {
public static void main(String[] args) {
int i = 1;
int j = ++i + i++ + ++i + ++i + i++;
//i value         2     3     4     5     6
// Value       2     2     4     5     5
System.out.println(j);
}
}
```
Example 11 :

practice -BMI

top fracture   Wrong posture , get half the results with double the effort ! Click to see the correct posture for the exercise
use Scanner Collect your height and weight , And calculate your BMI What is the value

BMI The formula is weight (kg) / ( height * height )

For example, Qiu Yangbo's weight is 72kg, Height is 1.69, So this classmate's BMI namely
72 / (1.69*1.69) = ?

reference resources : use Scanner How to read floating point numbers
Example 12 :

top fracture
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Viewing this answer will cost 4 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Viewing this answer will cost 4 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Account not activated , Limited functionality . Please click activate
This video is interpretive , So I hope you have read the content of this answer , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning

import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println(" Please enter your height (m):"); float height = s.nextFloat(); System.out.println(" Please enter your weight (kg):"); float weight = s.nextFloat(); float BMI = weight/ (height*height); System.out.println(" Current BMI yes : " + BMI); } }
```import java.util.Scanner;

public class HelloWorld {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
float height = s.nextFloat();
float weight = s.nextFloat();
float BMI = weight/ (height*height);
System.out.println(" Current BMI yes : " + BMI);
}
}
```

The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .

Q & A area
2021-10-05 It seems that it's OK to write like this , Not used long There should be no problem ？
 Evening star about JAVA Basics - Operator - Arithmetic operators - answer -BMI Your questions Is that ok , no need long, use double type , Because teachers use this type more ```Scanner i=new Scanner(System.in); System.out.println(" Please enter your height (m)："); double s=i.nextDouble(); System.out.println(" Please enter your weight (kg)："); double t=i.nextDouble(); double b=t/(s*s); if(b<18.5) { System.out.println(" Underweight "); }else if(18.5<=b&&b<24) { System.out.println(" normal range "); }else if(24<=b&&b<27){ System.out.println(" Overweight "); }else if(27<=b&&b<30) { System.out.println(" Mild obesity "); }else if(30<=b&&b<35) { System.out.println(" Moderate obesity "); }else if(345<=b) { System.out.println(" Severe obesity "); }else { System.out.println(" Don't enter data blindly "); } System.out.println(" Current BIM yes "+b); }```

JZLong
Hard working snail i
jonty99
package lian; import java.util.Scanner; public class shuru { public static void main(String[] args){ System.out.println(" Please enter your weight (kg)："); Scanner scanner = new Scanner(System.in); double weight = scanner.nextDouble(); System.out.println(" Please enter your height (m)："); //Scanner scanner = new Scanner(System.in); double height = scanner.nextDouble(); double BMI=weight/(height*height); System.out.println(BMI); }

Ogawa GG
c128ve980
package How2; import java.util.Scanner; public class ScannerTest { public static void main(String[] args) { System.out.println(" Please enter your weight (kg)："); Scanner scanner = new Scanner(System.in); double weight = scanner.nextDouble(); System.out.println(" Please enter your height (m)："); double height = scanner.nextDouble(); double BMI = weight/(height*height); System.out.println(BMI); } }
``` Please enter your weight (kg)：
85
1.75
27.755102040816325```

Yan Chan

answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see

2021-09-16 When casting , What shortcut key did you enter when ？ It changes in a moment
 wong11 about JAVA Basics - Operator - Arithmetic operators Your questions stay 5:41 When I was , What shortcut keys are entered for forced conversion ？ ```int i = 5; long j =61; int x = i+j;// Need to convert , What shortcut key is entered after selection ```

Hard working snail i
jonty99
package lian; import java.util.Scanner; public class shuru { public static void main(String[] args){ System.out.println(" Please enter your weight (kg)："); Scanner scanner = new Scanner(System.in); double weight = scanner.nextDouble(); System.out.println(" Please enter your height (m)："); //Scanner scanner = new Scanner(System.in); double height = scanner.nextDouble(); double BMI=weight/(height*height); System.out.println(BMI); }

answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see

2021-08-28 BMI practice
2021-07-23 Why? scanner s of s Will report an error
2021-07-03 calculation BMI Applet for

Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 99 Previous questions , please Click to view