java --基本数据类型间的转换
2024-09-20 12:25:42
public class changetype {
public static void main(String[] args)
{
String ar = "true"; //String转 boolean ,只要不是"true",结果即为false;
boolean ar1 = Boolean.parseBoolean(ar);
if(ar1)
{
System.out.println("true"); //结果为true;
} String str = "12"; //String 转 int
int m = Integer.parseInt(str);
System.out.println(m); String str0 = "12.6"; //string转换成double
double x = Double.parseDouble(str0);
System.out.println(x); int y = 5;
String str1 = y+"";
System.out.println(str1); int flag = 100; //int转String,任何类型与字符串连接将变为字符串类型。不推荐使用
String a = flag+"";
System.out.println(a); int flag0 = 200; //int 转String 利用String.valueOf();
String str3 = String.valueOf(flag0);
System.out.println(str3); float h = 12.6f; // float 转 int ,由高到低必须进行强制类型转换,损失精度变为12
int w =(int)h;
System.out.println(w); //结果为12 float c = 89.6666f;
double s = c;
System.out.println(s); //结果为89.666677987979 double e = 78.999999999;
float o = (float)e;
System.out.println(o); //结果为79 }}
最新文章
- Hadoop学习笔记—14.ZooKeeper环境搭建
- ios - block循环引用Demo示例
- bdb log file 预设长度的性能优化
- POJ 1502 MPI Maelstrom (Dijkstra)
- 《深入剖析Tomcat》阅读(二)
- windows 与Linux 互传文件
- cocos2d-x 3.0rc2 对于每个包执行情况的重要平台 (超级方便)
- SQL的各种连接(cross join、inner join、full join)的用法理解
- 中间件详解,Django复习
- WORDPRESS博客完美更换网站空间服务器的方法
- SecureCRT标签显示标题
- Python全栈之路----常用模块----hashlib加密模块
- 洛谷-p2764(最小路径覆盖)(网络流24题)
- centos查看端口被哪个应用端口占用命令
- QT插件+ROS 2 新建项目
- [UE4]解决角色影子的问题
- Q in Q
- eclipse 安装properties编辑器,显示中文
- Scala中使用implict 扩展现有类的方法
- AngularJS中Directive指令系列 - bindToController属性的使用
热门文章
- Java经典编程题50道之二十八
- PHP函数register_shutdown_function的用法
- python file文件操作--内置对象open
- HttpURLConnection发送请求
- 数据排序--vue
- R︱mlr包帮你挑选最适合数据的机器学习模型(分类、回归)+机器学习python和R互查手册
- R+tmcn笔记︱tmcn包的基本内容以及李舰老师R语言大会展示内容摘录
- HI3531的nand flash测试
- Java获取当前的年月
- Error Code: 1630. FUNCTION rand.string does not exist