java===java基礎學習(2)---運算子,三元操作符,數學函數

來源:互聯網
上載者:User

標籤:sof   常用   and   import   數學函數   ...   color   int   內建函數   

主要介紹運算子,和數學函數以及三元運算子:

package testbotoo;public class test1 {    public static void main(String[] args)    {        int a = 122;        System.out.println("調用operation的結果是:"+operation(a));  //調用下面定義的方法    };
public static int operation(int v){ int xe = v + 1; int and = 10; return xe ; }}

運算子,基本和python的類似,只是這裡用的是 &&  表示 and,用  || 表示 or :

        /*關係運算子*/        expression1 && expression2  //相當於python中的 expression1 and expression2        expression1 || expression2  //相當於python中的 expression1 or expression2        

三元操作符:

        /*三元操作符*/        condition ? expression1 : expression2   //當條件condition為真的時候,計算第一個運算式,否則計算第二個運算式

     例如:
     x < y ? x : y
     //上述就是求 x 和 y 中的的最小的一個

常用數學函數:

就相當於內建函數,已經實現的一些方法,屬於Math類。

Math.sin

Math.cos

Math.exp

Math.log

Math.log10

... ...

使用的時候先匯入:

import static java.lang.Math.*

這樣就省去了加上Math的麻煩。直接使用,sin,cos,tan等等。

 

 

 

java===java基礎學習(2)---運算子,三元操作符,數學函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.