java資料類型講解

來源:互聯網
上載者:User

標籤:java資料類型

資料類型講解

1、float型資料的輸入與輸出(用記事本寫的).

public class C2_2{    public static void main(String args[])    {        float x,y,z;        x=94.3f;        y=32.9f;        z=x/y;        System.out.println(x+"/"+y+"="+z);    }}123456789101112

輸出結果如下:
650) this.width=650;" src="http://img.blog.csdn.net/20150721135424016" alt="這裡寫圖片描述" title="" />

2、字元型變數

public class C2_3{    public static void main(String args[])    {        char c1,c2,c3;//聲明變數c1,c2,c3為字元型變數        c1=‘H‘;//在以c1為標識的儲存單元中存入字元H        c2=‘\\‘;//在以c2為標識的儲存單元中存入字元        c3=‘\115‘;//在以c3為標識的儲存單元中存入八位元115代表的ASCII字元M        System.out.print(c1);        System.out.print(c2);        System.out.print(c3);    }}

運行結果:
650) this.width=650;" src="http://img.blog.csdn.net/20150721163045686" alt="這裡寫圖片描述" title="" />

3、布爾型變數

public class C2_4{    public static void main(String args[])    {        boolean x,y,z;//聲明變數        int a=89,b=20;        x=(a>b);//對布爾型變數賦值        y=(a!=b);//對布爾型變數賦值        z=(a+b==43);//對布爾型變數賦值        System.out.println("x="+x);//輸出布爾型變數的值        System.out.println("y="+y);//輸出布爾型變數的值        System.out.println("z="+z);//輸出布爾型變數的值    }}

運行結果
650) this.width=650;" src="http://img.blog.csdn.net/20150721164338121" alt="這裡寫圖片描述" title="" />

本文出自 “桑海田 部落格專欄” 部落格,請務必保留此出處http://10602803.blog.51cto.com/10592803/1683051

java資料類型講解

聯繫我們

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