Java operators

1. Arithmetic operators:  

+, -, *, /, %, ++, -- Add, subtract, multiply, divide, modulo, increment, decrement

int num1 = 10;
int num2 = 20; int result = num1+num2; System.out.println(result);//30 System.out.println(num1-num2);//-10 System.out.println( num1*num2);//200 System.out.println(num1/num2);//0 System.out.println(num2%3);//Remainder--- 2 //ps:byte, short when doing operations , it will be automatically converted to int type and then do the operation, so the result obtained is int type byte b1 = 1; byte b2 = 2; byte sum = (byte)(b1 + b2); System.out.println(sum); / /++ increment by 1 int a = 10; //++a : increment by 1 first, then use //a++ : use first, increment by 1





















ps:     

                            a++;

                            System.out.println(a); At this time, the output is 11 a++ is replaced by a--the output is still 11 

                                                                  The value of a that is output because the a++ or a-- statement has completed the operation before the output statement






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324841819&siteId=291194637