
9.2 字符串与基本数据类型的相互转化
发布日期:2021-05-07 06:40:02
浏览次数:21
分类:精选文章
本文共 781 字,大约阅读时间需要 2 分钟。
- 使用java.lang 包中的Integer类调用其类方法(Integer.方法)
- public static int parseInt(String s)
可以将由“数字”字符组成的字符串,转化为int型数据
Int x;String s=”123456”;x=Integer.parseInt(s);
类似的Byte,Short,Float,Double也是差不多的,如Byte
- public static byte parseByte(String s) throws NumberFormatException
可以将由“数字”组成的字符串转化为相应的基本数据类型
- 可以使用String类的下列方法(String.方法)
- public static String valueOf(byte n)
将形如123,1232.98等数值转化为字符串,如String str=String.valueOf(12.13);
int,long,float,double也是一样,不详细写了
- 可以使用Long类中的下列类方法得到整数的各种进制的字符串表示:(Long.方法)
public static String toBinaryString(long i)
public static String toOctalString(long i)
public static String toHexString(long i)
public static String toString(long i,int p)
其中的toString(long i,int p)返回整数i的p进制
还有一种输入是使用main方法中 的参数args,不过我在idea没反应
直接这样编译倒是可以
这样的话args[0],args[1],args[2]的值为12.89,35和78
发表评论
最新留言
关注你微信了!
[***.104.42.241]2025年04月24日 00时20分07秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
leaflet面采集与面编辑(leaflet篇.7)
2023-01-30
leaflet饼状图(leaflet篇.74)
2023-01-30
Leedcode3- Max Points on a Line 共线点个数
2023-01-30
LeetCode OJ:Merge k Sorted Lists(归并k个链表)
2023-01-31
leetcode Plus One
2023-01-31
LeetCode Text Justification
2023-01-31
Leetcode | Simplify Path
2023-01-31
LeetCode – Refresh – 4sum
2023-01-31
leetCode 字符串反转
2023-01-31
LeetCode(229):Majority Element ||
2023-01-31
leetcode--
2023-01-31
LeetCode--020--括号匹配
2023-01-31
Leetcode-966 Vowel Spellchecker(元音拼写检查器)
2023-01-31
LeetCode111.二叉树最小深度
2023-01-31
leetcode23-合并K个升序链表
2023-01-31
LeetCode268.缺失数字
2023-01-31
LeetCode331.验证二叉树的前序序列化
2023-01-31
Leetcode: Spiral Matrix II
2023-01-31
LeetCode: String to Integer (atoi)
2023-01-31
Leetcode:454. 4Sum II
2023-01-31