日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

字符串是什么意思 字符怎么輸入


字符串是什么意思 字符怎么輸入


9.1 裝箱拆箱封裝類所有的基本類型,都有對(duì)應(yīng)的類類型 。比如int對(duì)應(yīng)的類是Integer,這種類就叫做封裝類 。
package digit;public class TestNumber {public static void main(String[] args) {int i = 5;//把一個(gè)基本類型的變量 , 轉(zhuǎn)換為Integer類型Integer it = new Integer(i);//把一個(gè)Integer對(duì)象,轉(zhuǎn)換為一個(gè)基本類型的intint i2 = it.intValue();}}Number類數(shù)字封裝類有Byte,Short,Integer,Long,Float,Double 。這些類都是抽象類Number的子類 。

自動(dòng)裝箱與拆箱不需要調(diào)用構(gòu)造方法,通過**=**符號(hào)自動(dòng)把 基本類型 轉(zhuǎn)換為 類類型 就叫裝箱
不需要調(diào)用Integer的intValue方法 , 通過**=就自動(dòng)轉(zhuǎn)換成int類型**,就叫拆箱
package digit; public class TestNumber {public static void main(String[] args) {int i = 5;//基本類型轉(zhuǎn)換成封裝類型Integer it = new Integer(i);//自動(dòng)轉(zhuǎn)換就叫裝箱Integer it2 = i;//封裝類型轉(zhuǎn)換成基本類型int i2 = it.intValue();//自動(dòng)轉(zhuǎn)換就叫拆箱int i3 = it;}}
int的最大值和最小值int的最大值可以通過其對(duì)應(yīng)的封裝類Integer.MAX_VALUE獲取
package digit;public class TestNumber {public static void main(String[] args) {//int的最大值System.out.println(Integer.MAX_VALUE);//int的最小值System.out.println(Integer.MIN_VALUE);}
9.2字符串轉(zhuǎn)換
數(shù)字轉(zhuǎn)成字符串【字符串是什么意思 字符怎么輸入】方法1: 使用String類的靜態(tài)方法valueOf 方法2: 先把基本類型裝箱為對(duì)象,然后調(diào)用對(duì)象的toString
package digit;public class TestNumber {public static void main(String[] args) {int i = 5;//方法1String str = String.valueOf(i);//方法2Integer it = i;String str2 = it.toString();}}
字符串轉(zhuǎn)成數(shù)字調(diào)用Integer的靜態(tài)方法parseInt
package digit;public class TestNumber {public static void main(String[] args) {String str = "999";int i= Integer.parseInt(str);System.out.println(i);}}
練習(xí)把浮點(diǎn)數(shù) 3.14 轉(zhuǎn)換為 字符串 "3.14" 再把字符串 “3.14” 轉(zhuǎn)換為 浮點(diǎn)數(shù) 3.14
如果字符串是 3.1a4,轉(zhuǎn)換為浮點(diǎn)數(shù)會(huì)得到什么?
public class TestNumber {public static void main(String[] args) {double i = 3.14;String str = String.valueOf(i);System.out.println("3.14轉(zhuǎn)換成的字符串 " + str);double i2 = Float.parseFloat(str);System.out.println("\"3.14\"轉(zhuǎn)換成的浮點(diǎn)數(shù) " + i2);String str2 = "3.1a4";double i3 = Float.parseFloat(str2);System.out.println("\"3.1s4\"轉(zhuǎn)換成的浮點(diǎn)數(shù) " + i3);}}

9.3數(shù)學(xué)方法
四舍五入, 隨機(jī)數(shù),開方,次方,π,自然常數(shù)public class TestNumber {public static void main(String[] args) {float f1 = 5.4f;float f2 = 5.5f;//5.4四舍五入即5System.out.println(Math.round(f1));//5.5四舍五入即6System.out.println(Math.round(f2));//得到一個(gè)0-1之間的隨機(jī)浮點(diǎn)數(shù)(取不到1)System.out.println(Math.random());//得到一個(gè)0-10之間的隨機(jī)整數(shù) (取不到10)System.out.println((int)( Math.random()*10));//開方System.out.println(Math.sqrt(9));//次方(2的4次方)System.out.println(Math.pow(2,4));//πSystem.out.println(Math.PI);//自然常數(shù)System.out.println(Math.E);}}
練習(xí)-數(shù)學(xué)方法

public class TestNumber {public static void main(String[] args) {int n = Integer.MAX_VALUE;double value = http://www.fzline.cn//sh/Math.pow((1 + 1/(double)n),n);System.out.println("n 取最大整數(shù)時(shí)value: " + value);double error = Math.abs(Math.E - value);System.out.println("error = " + error);}}

推薦閱讀