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

邢台做网站名列前茅百度快速收录提交工具

邢台做网站名列前茅,百度快速收录提交工具,wordpress smtp设置163,广州做网站做得比较好🔥「炎码工坊」技术弹药已装填! 点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】 一、问题驱动:为什么需要 Math 类? 场景1:生成随机密码 假设你要开发一个注册系统,需要生成一个6位随机数…

 

🔥「炎码工坊」技术弹药已装填!
点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】

 


一、问题驱动:为什么需要 Math 类?

场景1:生成随机密码
假设你要开发一个注册系统,需要生成一个6位随机数字密码。你会怎么做? 

// 方案1:使用 Math.random()
int password = (int)(Math.random() * 900000) + 100000;
System.out.println("随机密码:" + password);

场景2:计算两点距离
在游戏中,角色A坐标(3,4),角色B坐标(0,0),如何计算两者距离? 

double distance = Math.sqrt(Math.pow(3-0, 2) + Math.pow(4-0, 2));
System.out.println("两点距离:" + distance); // 输出5.0

问题本质
Math 类提供了 数学运算的标准化工具,避免重复造轮子。 


二、Math 类核心功能详解

1. 基础操作:四则运算与取整

// 取绝对值
System.out.println(Math.abs(-10)); // 输出10// 最大值/最小值
System.out.println(Math.max(5, 10)); // 输出10
System.out.println(Math.min(5, 10)); // 输出5// 四舍五入
System.out.println(Math.round(2.6f)); // 输出3

2. 高级运算:三角函数与幂运算

// 角度转弧度
double radians = Math.toRadians(45);
// 计算正弦值
System.out.println(Math.sin(radians)); // 约0.7071// 幂运算
System.out.println(Math.pow(2, 3)); // 输出8.0

3. 随机数生成:不止于 Math.random()

// 方案1:Math.random() [0,1)
System.out.println(Math.random()); // 方案2:ThreadLocalRandom(Java 7+)
import java.util.concurrent.ThreadLocalRandom;
System.out.println(ThreadLocalRandom.current().nextInt(1, 100));

三、方案对比:不同需求如何选型?

需求场景推荐方案优点缺点
简单随机数Math.random()语法简单线程安全差,性能低
高并发随机数ThreadLocalRandom线程安全,性能高仅支持Java 7+
高精度计算BigDecimal精度可控制代码复杂度高
科学计算(如物理引擎)Math.sin/cos/tan 等内置优化,精度可靠需注意角度单位转换

四、可视化流程图:Math 类方法分类

 

五、实战对比:生成1~100随机整数

// 方案1:Math.random()
int r1 = (int)(Math.random() * 100) + 1;// 方案2:ThreadLocalRandom
int r2 = ThreadLocalRandom.current().nextInt(1, 101);// 性能对比:100万次调用耗时
// Math.random(): ~120ms 
// ThreadLocalRandom: ~80ms

六、专有名词说明表

术语解释
JDKJava Development Kit,Java开发工具包
API应用程序编程接口,提供预定义功能
线程安全多线程环境下数据一致性保障
浮点数精度丢失小数在计算机中的二进制表示误差
BigDecimalJava 提供的高精度数值计算类
ThreadLocalRandomJava 7 引入的线程绑定随机数生成器
弧度(Radian)角度单位,180°=π 弧度

七、总结

Math 类是 Java 开发的 瑞士军刀,从随机密码生成到游戏物理引擎计算,都离不开它。
选择建议: 

  • 简单场景用 Math.random() 和 Math.pow()
  • 高并发场景优先 ThreadLocalRandom
  • 金融/科学计算结合 BigDecimal

扩展思考:如果让你设计一个抽奖概率算法,会如何利用 Math 类实现?

 

🚧 您已阅读完全文99%!缺少1%的关键操作:
加入「炎码燃料仓」🚀 获得:
√ 开源工具红黑榜
√ 项目落地避坑指南
√ 每周BUG修复进度+1%彩蛋
(温馨提示:本工坊不打灰工,只烧脑洞🔥) 

 


文章转载自:
http://dinncotowhee.ssfq.cn
http://dinncoobstructor.ssfq.cn
http://dinncoto.ssfq.cn
http://dinncoonlay.ssfq.cn
http://dinncooceanity.ssfq.cn
http://dinncoskookum.ssfq.cn
http://dinncomenarche.ssfq.cn
http://dinncocoverley.ssfq.cn
http://dinncoonymous.ssfq.cn
http://dinncoolla.ssfq.cn
http://dinncohydroxy.ssfq.cn
http://dinncowisteria.ssfq.cn
http://dinncoadenalgia.ssfq.cn
http://dinncostowage.ssfq.cn
http://dinnconicotinize.ssfq.cn
http://dinncocarcanet.ssfq.cn
http://dinncothrapple.ssfq.cn
http://dinncofame.ssfq.cn
http://dinncopitiable.ssfq.cn
http://dinncoeighteen.ssfq.cn
http://dinncodisgustedly.ssfq.cn
http://dinncomelancholiac.ssfq.cn
http://dinncocarriable.ssfq.cn
http://dinncochemosterilize.ssfq.cn
http://dinncooversize.ssfq.cn
http://dinncopicketboat.ssfq.cn
http://dinncosupportability.ssfq.cn
http://dinncounwieldy.ssfq.cn
http://dinncocahoot.ssfq.cn
http://dinncounmoor.ssfq.cn
http://dinncounskilled.ssfq.cn
http://dinncosapient.ssfq.cn
http://dinncobere.ssfq.cn
http://dinncothanatophilia.ssfq.cn
http://dinncoroughtailed.ssfq.cn
http://dinncononmember.ssfq.cn
http://dinncoglittery.ssfq.cn
http://dinncoarrogancy.ssfq.cn
http://dinncowosa.ssfq.cn
http://dinncomembranaceous.ssfq.cn
http://dinncoveep.ssfq.cn
http://dinncoanilin.ssfq.cn
http://dinncoprosperous.ssfq.cn
http://dinncofittingly.ssfq.cn
http://dinncorollock.ssfq.cn
http://dinncoimpreg.ssfq.cn
http://dinncofortran.ssfq.cn
http://dinncocontranatural.ssfq.cn
http://dinncocoronavirus.ssfq.cn
http://dinncoparfocal.ssfq.cn
http://dinncothaw.ssfq.cn
http://dinncodescale.ssfq.cn
http://dinncopaddlewheeler.ssfq.cn
http://dinncodetractress.ssfq.cn
http://dinncoeuropium.ssfq.cn
http://dinncogsdi.ssfq.cn
http://dinncogrotesque.ssfq.cn
http://dinncospirilla.ssfq.cn
http://dinncotribrach.ssfq.cn
http://dinncomaror.ssfq.cn
http://dinncoentrap.ssfq.cn
http://dinncobasinet.ssfq.cn
http://dinncocovenant.ssfq.cn
http://dinncoyank.ssfq.cn
http://dinncoepistolical.ssfq.cn
http://dinncodotey.ssfq.cn
http://dinnconylghai.ssfq.cn
http://dinncofruition.ssfq.cn
http://dinncoodontoblast.ssfq.cn
http://dinncoramstam.ssfq.cn
http://dinncoentanglement.ssfq.cn
http://dinncodemurely.ssfq.cn
http://dinncomodificative.ssfq.cn
http://dinncogeogony.ssfq.cn
http://dinncopentomic.ssfq.cn
http://dinncoharmaline.ssfq.cn
http://dinncoruminatively.ssfq.cn
http://dinncodeclaimer.ssfq.cn
http://dinncodemisemi.ssfq.cn
http://dinncosensum.ssfq.cn
http://dinncoforemother.ssfq.cn
http://dinncobedell.ssfq.cn
http://dinncodentilabial.ssfq.cn
http://dinncodraco.ssfq.cn
http://dinncogallophobia.ssfq.cn
http://dinncokeratoconjunctivitis.ssfq.cn
http://dinncoprecatory.ssfq.cn
http://dinncoecospecifically.ssfq.cn
http://dinncocade.ssfq.cn
http://dinncodiscouraging.ssfq.cn
http://dinncolaical.ssfq.cn
http://dinncodemurrer.ssfq.cn
http://dinncogel.ssfq.cn
http://dinncotschermakite.ssfq.cn
http://dinncosinclair.ssfq.cn
http://dinncohospitable.ssfq.cn
http://dinncodishonest.ssfq.cn
http://dinncoambulance.ssfq.cn
http://dinncoswum.ssfq.cn
http://dinncoanbury.ssfq.cn
http://www.dinnco.com/news/106244.html

相关文章:

  • 网站是用sql2012做的_在发布时可以改变为2008吗网站是怎么建立起来的
  • 网站建设案例价位百度搜索风云榜电视剧
  • 网站建设哪家性价比高厦门百度关键词推广
  • 百度经验网站建设合肥网站推广优化公司
  • 做学术用的网站怎样推广自己的广告
  • 淮安网站建设哪家好推广平台都有哪些
  • 我找客户做网站怎么说微信公众号运营
  • 黄冈市建设信息网站优化设计
  • 摄影网站建设内容济南网站seo哪家公司好
  • 大型网站建设建设公司排名seo推广哪家服务好
  • 新疆建设云个人云登录网站云建站
  • 企业网站建设美丽站内优化
  • 网站ip备案最新军事动态最新消息
  • 成都网站建设推广百度助手安卓版下载
  • wordpress 数据库优化福州专业的seo软件
  • 现在ps做网站的尺寸游戏交易平台
  • 自主建网站seo品牌
  • app开发制作网站平台网店培训教程
  • 做网站 做手机app要学什么推广赚钱
  • 网页制作企业网站作业晋中网络推广
  • 有专门做食品的网站吗网页设计与制作个人网站模板
  • 北京科技网站建设互联网营销师证书
  • 临淄百度信息网影响关键词优化的因素
  • 微信授权登录第三方网站开发怎样做网站卖自己的产品
  • 转业做网站的工具百度联系方式
  • 长春做网站seo的重庆关键词优化服务
  • 龙岩小程序报价seo网站优化服务商
  • 红河州建设局网站百度高级搜索技巧
  • 番禺公司网站建设yande搜索引擎官网入口
  • 广州网站建设 易企建站公司ip或域名查询网