JAVA 基礎 /第十二課: 操作符 / JAVA的所有操作符1,java操作符

來源:互聯網
上載者:User

JAVA 基礎 /第十二課: 操作符 / JAVA的所有操作符1,java操作符

2018-03-07

一、JAVA的算數操作符

1.基本算數操作符

基本的加 減 乘 除:+ - * /

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;    }}
2.%模數

% 取餘數,又叫模數......5除以2,餘1

public class HelloWorld {    public static void main(String[] args) {         int i = 5;        int j = 2;        System.out.println(i%j); //輸出為1    }}: 
3.自增 自減

在原來的基礎上增加1或者減少1:++ 和-- 

public class HelloWorld {    public static void main(String[] args) {         int i = 5;        i++;        System.out.println(i);//輸出為6     }}

自增 自減操作符置前以及置後的區別:

以++為例 
int i = 5; 
i++; 先取值,再運算 
++i; 先運算,再取值

public class HelloWorld {    public static void main(String[] args) {        int i = 5;        System.out.println(i++); //輸出5        System.out.println(i);   //輸出6                 int j = 5;        System.out.println(++j); //輸出6        System.out.println(j);   //輸出6    }}

二、JAVA的關係操作符

1.關係操作符:比較兩個變數之間的關係 
> 大於 
>= 大於或等於 
< 小於 
<= 小於或等於 
== 是否相等 
!= 是否不等 

public class HelloWorld {    public static void main(String[] args) {       int a = 5;       int b = 6;       int c = 5;               System.out.println(a>b);  //返回 false       System.out.println(a>=c);  //返回 true               System.out.println(a==b); //返回false       System.out.println(a!=b);//返回true            }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.