inotgo.com


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
This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers



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 12 : answer -BMI   

Example 1 :

Basic arithmetic operators

edit 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

edit 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
 practice - Sum
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 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

2 branch 2 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers


 answer - Sum
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

edit 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

edit 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;
	}
}
% 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

edit 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

edit 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

edit 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
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 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

2 branch 26 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers


 answer - Self increasing
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

edit 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
 practice -BMI
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 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

4 branch 19 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers


 answer -BMI
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);
    	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);
    }
}


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




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);
	    	
	}
 
               


6 One answer

JZLong
Answer time :2021-11-03
Hard working snail i
Answer time :2021-10-30
jonty99
Answer time :2021-10-19
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
Answer time :2021-10-17
c128ve980
Answer time :2021-10-15
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
 Please enter your height (m):
1.75
27.755102040816325

Yan Chan
Answer time :2021-10-10



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
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




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 
 
               


2 One answer

Hard working snail i
Answer time :2021-10-30
jonty99
Answer time :2021-10-19
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); }



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
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

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about JAVA Basics - Operator - Arithmetic operators Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot