当前位置: 首页 > news >正文

基本数据类型转换

基本数据类型转换

public class ch04_typechange {public static void main(String[] args) {//byte,short,char -> int -> long -> float -> double(低->高)int i = 128;double b = i;//强制转换  (类型)变量名     高--低//自动转换  低--高System.out.println(i);System.out.println(b);/*1.不能对Boolean类型转换2.不能把对象类型转换为不相干的类型3.在把高容量转换到低容量的时候,强制转换4.转换的时候可能存在内存溢出或者精度问题*/System.out.println((int)20.9);//20System.out.println((int)-45.88f);//-45char c = 'a';int d = c+1;System.out.println(d);System.out.println((char)d);

内存溢出问题的处理

//操作比较大的数的时候,注意溢出问题
//jdk7新特性,数字之间可以用下划线分割
int money = 10_0000_0000;
int years = 20;
int total = money*years;//-147486480,计算的时候内存溢出了
long total2 = money*years;//默认是int,转换之前已经出问题了
long total3 = money*(long)years;//先把一个数转换为long
System.out.println(total3);
http://www.wxhsa.cn/company.asp?id=946

相关文章:

  • C# Avalonia 13- MoreDrawing - VisualLayer
  • Linux 设置nginx 以及java jar自启动
  • DevelPy-TryHackMe
  • 记录一次解决phpstudy启动数据库自动关闭的问题方法
  • cache redis
  • 《爱上情感:自然魅力的社交》
  • Java的基本数据类型
  • H5游戏性能优化系列-----配置相关优化
  • 300 毫秒生成情感 AI 视频,Nuance Labs 获千万美元融资;AirPods Pro 3 将集成实时语音翻译丨日报
  • 认知引擎:企业下一个决胜分水岭
  • node.js安装地址
  • 【已解决】git Encountered 3 file(s) that should have been pointers, but werent
  • 接雨水-leetcode
  • Codeforces Round 1049 (Div. 2) E
  • ES深度分页优化
  • 2025年8月国产数据库大事记:东莞银行1078万采购OceanBase、821万采购腾讯TDSQL,2025上半年达梦净利2亿、金仓净利润飙升……
  • VSCode安装Jupyter的常见问题
  • 批量设置Excel样式格式(如:纸张大小,排版,字体等)+ 支持windows系统
  • 张瑜:牛市进程之十大观察指标 - Leone
  • QT-控件使用-获取lable标签宽高尺寸设置图片
  • 初识python:一些基础的知识(推导式)
  • RK3588+preemrt+ethercat搭建
  • Windows 11 系统优化
  • 碎碎念(十六)
  • PK-2600-ALG-2 三同轴转鳄鱼夹测试线应用案例
  • RK3588+xenomai3+ethercat搭建
  • 从英伟达到国产算力:一场必须打赢的“迁移之战”
  • 小说写法分析-个人随记
  • Nuget的不是所配置的源之一
  • part 3