大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 學習攻略 Java學習 Java八大數據類型的詳細介紹

Java八大數據類型的詳細介紹

更新時間:2022-06-02 10:20:51 來源:動力節點 瀏覽1993次

Java 是一種強類型語言。這意味著,在 Java 中,每種數據類型都有自己的嚴格定義。當數據類型之間發生任何沖突時,不存在隱式數據類型轉換。數據類型的任何更改都應由程序員明確聲明。

Java 定義了8 種原始數據類型:byte、short、int、long、char、float和.doubleboolean

它們分為以下幾類:

整數

浮點數字

人物

布爾類型

每種數據類型的詳細信息如下:

整數:

它們有四種類型:byte, short, int, long。重要的是要注意這些是有符號的正值和負值。有符號整數使用2 的補碼存儲在計算機中。它包含負值和正值,但格式不同,例如(-1 to -128)or (0 to +127)。無符號整數可以容納更大的正值,而沒有像(0 to 255). 與 C++ 不同,Java 中沒有無符號整數。

字節:

字節數據類型是一個 8 位有符號二進制補碼整數。

Wrapper Class: Byte
Minimum value: -128 (-2^7)
Maximum value: 127 (2^7 -1)
Default value: 0
Example: byte a = 10 , byte b = -50;

短的:

短數據類型是 16 位有符號二進制補碼整數。

Wrapper Class: Short
Minimum value: -32,768 (-2^15)
Maximum value: 32,767 (2^15 -1)
Default value: 0.
Example: short s = 10, short r = -1000;

詮釋:

int 數據類型是一個 32 位有符號二進制補碼整數。它通常用作整數值的默認數據類型,除非存在內存問題。

Wrapper Class: Integer
Minimum value: (-2^31)
Maximum value: (2^31 -1)
The default value: 0.
Example: int a = 50000, int b = -20

長:

Long 數據類型是一個 64 位有符號二進制補碼整數。

Wrapper Class: Long
Minimum value: (-2^63)
Maximum value: (2^63 -1)
Default value: 0L.
Example: long a = 100000L, long b = -600000L; 
By default all integer type variable is "int". So long num=600851475143  will give an error.
But it can be specified as long by appending the suffix L (or l)

浮點數?:

這些也稱為實數,用于涉及小數精度的表達式。它們有兩種類型:float, double。在貨幣或研究數據等精確數據的情況下,實際上避免了浮動。

漂浮:

float 數據類型是單精度 32 位IEEE 754 浮點數。

Wrapper Class: Float
Float is mainly used to save memory in large arrays of floating point numbers.
Default value: 0.0f.
Example: float f1 = 24.5f;
The default data type of floating-point number is double. So float f = 24.5 will introduce an error.
However, we can append the suffix F (or f) to designate the data type as float.

雙倍的:

double 數據類型是雙精度 64 位IEEE 754 浮點。此數據類型通常是默認選擇。此數據類型絕不應用于精確值,例如貨幣。

Wrapper Class: Double
This data type is generally used as the default data type for decimal values.
Default value: 0.0d.
Example: double d1 = 123.400778;

特點:

我們使用這種數據類型來存儲字符。這與 C/C++ 中的 char 不同。Java 使用UNICODE國際公認的字符集。Java 中的字符為 16 位,而 C/C++ 中的字符為 8 位。

Wrapper Class: Character
Minimum value: '\u0000' (or 0).
Maximum value: '\uffff' (or 65,535).
Default value: null ('\u0000').
Example: char letterA ='a';

布爾值:

這用于存儲邏輯值。布爾類型的值可以是真或假。這種類型通常由關系運算符返回。

There are only two possible values: true and false.
Wrapper Class: Boolean
This data type is used for simple flags that track true/false conditions.
Default value is false.
Example: boolean b = true, boolean b1 = 1(this is not possible in java and give incompatible type error), boolean b2;

參考數據類型:

除了原始數據類型之外,還有使用不同類的構造函數創建的引用變量。引用變量可用于任何類以及數組、字符串、掃描儀、隨機數、模具等。使用新關鍵字初始化引用變量。

例子 :

public class Box{
    int length, breadth, height;
    public Box(){
        length=5;
        breadth=3;
        height=2;
    }
}
class demo{
    public static void main(String args[]) {
        Box box1 = new Box();                //box1 is the reference variable  
        char[] arr = new char[10];           //arr is the reference variable
    }
}

細繩:

String 不是原始數據類型,但它允許您將多個字符數據類型存儲在一個數組中,并且有許多可以使用的方法。當用戶輸入數據并且您必須對其進行操作時,它非常常用。

在下面的示例中,我們嘗試從字符串中刪除所有字母并將其輸出:

String input = "My birthday is 10 January 1984 and my favorite number is 42";
String output = "";
for(int i=0;i<input.length();i++){
//if the character at index i on the string is a letter or a space, move on to the next index
if(Character.isLetter(input.charAt(i)) || input.charAt(i)==' '){     
    continue;
}
output = output + input.charAt(i); //the number is added onto the output
}
System.out.println(output);

輸出:

10198442

 

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 久久久国产精品免费看 | 美女福利在线观看 | 在线a网| 久久久国产这里有的是精品 | 五月婷婷综合在线 | 中文字幕不卡在线高清 | 福利视频在线观看午夜 | 久久免视频 | 精品国产97在线观看 | 精品久久久99大香线蕉 | 日日操干| 成人免费视频在线 | 色18美女社区 | 久久综合久久鬼色 | 毛片a级| 亚洲一区二区免费视频 | 天天操天天插天天射 | 女bbwxxxx高清| 伊人久久亚洲综合 | 欧美乱妇高清视频免欢看关 | 四虎影院在线观看网站 | 精品亚洲综合久久中文字幕 | 性欧美视频a毛片在线播放 性欧美视频在线观看 | 国产精品66在线观看 | 亚洲天天在线日亚洲洲精 | 久久久久久久免费视频 | 番茄视频在线观看黄版本免费 | 成人国产精品久久久免费 | 99热精品在线观看 | 四虎在线看 | 中文字幕日韩在线一区国内 | 欧美乱大交xxxxx另类 | 亚洲婷婷丁香 | 免费一级欧美大片在线观看 | 九九九精品视频免费 | 精品在线小视频 | 四虎影视国产永久免费 | 四虎永久免费影院在线 | 亚洲韩精品欧美一区二区三区 | 亚洲精品久久久午夜伊人 | 国产福利福利视频 |