題目:字符串逆序輸出
代碼:
vauleOf():The valueOf method returns the relevant Number Object holding the value of the argument passed. The argument can be a PRimitive data type, String, etc.This method is a static method. The method can take two arguments, where one is a String and the other is a radix.Return Vaule:valueOf(int i) ? This returns an Integer object holding the value of the specified primitive.
valueOf(String s) ? This returns an Integer object holding the value of the specified string representation.
valueOf(String s, int radix) ? This returns an Integer object holding the integer value of the specified string representation, parsed with the value of radix.
public class Test { public static void main(String args[]) { Integer x =Integer.valueOf(9); Double c = Double.valueOf(5); Float a = Float.valueOf("80"); Integer b = Integer.valueOf("444",16); System.out.println(x); System.out.println(c); System.out.println(a); System.out.println(b); }}95.080.01092String 類別中已經提供了將基本數據型態轉換成 String 的 static 方法 也就是 String.valueOf() 這個參數多載的方法 有下列幾種 String.valueOf(boolean b) : 將 boolean 變量 b 轉換成字符串 String.valueOf(char c) : 將 char 變量 c 轉換成字符串 String.valueOf(char[] data) : 將 char 數組 data 轉換成字符串 String.valueOf(char[] data, int offset, int count) : 將 char 數組 data 中 由 data[offset] 開始取 count 個元素 轉換成字符串 String.valueOf(double d) : 將 double 變量 d 轉換成字符串 String.valueOf(float f) : 將 float 變量 f 轉換成字符串 String.valueOf(int i) : 將 int 變量 i 轉換成字符串 String.valueOf(long l) : 將 long 變量 l 轉換成字符串 String.valueOf(Object obj) : 將 obj 對象轉換成 字符串, 等于 obj.toString() 用法如: int i = 10; String str = String.valueOf(i); 這時候 str 就會是 "10" 2. 由 String 轉換成 數字的基本數據型態 要將 String 轉換成基本數據型態轉 大多需要使用基本數據型態的包裝類別 比如說 String 轉換成 byte 可以使用 Byte.parseByte(String s) 這一類的方法如果無法將 s 分析 則會丟出 NumberFormatException byte : Byte.parseByte(String s) : 將 s 轉換成 byte Byte.parseByte(String s, int radix) : 以 radix 為基底 將 s 轉換為 byte 比如說 Byte.parseByte("11", 16) 會得到 17 double : Double.parseDouble(String s) : 將 s 轉換成 double float : Double.parseFloat(String s) : 將 s 轉換成 float int : Integer.parseInt(String s) : 將 s 轉換成 int long : Long.parseLong(String
新聞熱點
疑難解答