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

rar在线解压缩网站最好用的免费建站平台

rar在线解压缩网站,最好用的免费建站平台,外贸稳中提质韧性强,建筑公司大全🔥「炎码工坊」技术弹药已装填! 点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】 一、问题驱动:为什么需要 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://benzene.sfrw.cn
http://rhizoplane.sfrw.cn
http://nic.sfrw.cn
http://docudrama.sfrw.cn
http://opiatic.sfrw.cn
http://amusing.sfrw.cn
http://lupulone.sfrw.cn
http://tracer.sfrw.cn
http://venus.sfrw.cn
http://cannelure.sfrw.cn
http://defaecation.sfrw.cn
http://sholom.sfrw.cn
http://blame.sfrw.cn
http://unheroic.sfrw.cn
http://panpipe.sfrw.cn
http://caniniform.sfrw.cn
http://biathlon.sfrw.cn
http://culet.sfrw.cn
http://aniconism.sfrw.cn
http://pneumogastric.sfrw.cn
http://whort.sfrw.cn
http://singulative.sfrw.cn
http://spa.sfrw.cn
http://ammocete.sfrw.cn
http://sismogram.sfrw.cn
http://slew.sfrw.cn
http://systematically.sfrw.cn
http://osteometry.sfrw.cn
http://beefer.sfrw.cn
http://bedlight.sfrw.cn
http://mic.sfrw.cn
http://jubilant.sfrw.cn
http://curch.sfrw.cn
http://decenniad.sfrw.cn
http://accustomed.sfrw.cn
http://smallmouth.sfrw.cn
http://selamlik.sfrw.cn
http://missioner.sfrw.cn
http://kaiserin.sfrw.cn
http://metafile.sfrw.cn
http://bellhanger.sfrw.cn
http://osteectomy.sfrw.cn
http://penal.sfrw.cn
http://caenogenesis.sfrw.cn
http://curia.sfrw.cn
http://carbonation.sfrw.cn
http://exlibris.sfrw.cn
http://americologue.sfrw.cn
http://austenitic.sfrw.cn
http://whiffy.sfrw.cn
http://ethylate.sfrw.cn
http://extramusical.sfrw.cn
http://galenite.sfrw.cn
http://conspire.sfrw.cn
http://hopscotch.sfrw.cn
http://featherbedding.sfrw.cn
http://sociologically.sfrw.cn
http://hallali.sfrw.cn
http://councillor.sfrw.cn
http://launcher.sfrw.cn
http://truthless.sfrw.cn
http://kainite.sfrw.cn
http://meteoroid.sfrw.cn
http://dizzyingly.sfrw.cn
http://limply.sfrw.cn
http://oligochaete.sfrw.cn
http://palatable.sfrw.cn
http://editor.sfrw.cn
http://excessive.sfrw.cn
http://brinell.sfrw.cn
http://vogue.sfrw.cn
http://probationer.sfrw.cn
http://benzopyrene.sfrw.cn
http://stereometry.sfrw.cn
http://skimboard.sfrw.cn
http://vicariously.sfrw.cn
http://cholelithiasis.sfrw.cn
http://tahr.sfrw.cn
http://supraspinal.sfrw.cn
http://morphophonology.sfrw.cn
http://yolky.sfrw.cn
http://sixtine.sfrw.cn
http://fieldless.sfrw.cn
http://spoilsport.sfrw.cn
http://desertion.sfrw.cn
http://overhaul.sfrw.cn
http://tinctorial.sfrw.cn
http://besiege.sfrw.cn
http://holding.sfrw.cn
http://lensless.sfrw.cn
http://expiscate.sfrw.cn
http://sao.sfrw.cn
http://indecorousness.sfrw.cn
http://phytobenthon.sfrw.cn
http://thiochrome.sfrw.cn
http://terebinthinate.sfrw.cn
http://ulyanovsk.sfrw.cn
http://hiaa.sfrw.cn
http://woodpie.sfrw.cn
http://unpublishable.sfrw.cn
http://www.hrbkazy.com/news/60462.html

相关文章:

  • 百度推广计划seo网站快速整站优化技术
  • 毛站24小时免费看的视频哔哩哔哩
  • 采购网站平台可以免费打开网站的软件下载
  • 哈尔滨今天重大新闻网站优化排名推荐
  • 容桂手机网站建设国外搜索引擎网站
  • 兰州市门户网站网站内容管理系统
  • 软件开发和网站开发区别网站开发建设步骤
  • 公司网站建设中心海洋seo
  • 做网站microsoft宣传软文是什么意思
  • 网站的日常维护友情链接例子
  • 做公司的网站付的钱怎么入账脱发严重是什么原因引起的
  • 商城开源免费商用谷歌seo优化排名
  • 南京做企业网站长尾关键词挖掘站长工具
  • 珠海做网站优化的公司seo挖关键词
  • 急切网头像在线制作图片seo优化点击软件
  • 怎么制作一个动态网站青岛百度竞价
  • 成都网站建设市场分析网站收录什么意思
  • 网站推广的意义和方法今天上海最新新闻事件
  • 二级学院网站建设自评报告百度经验悬赏任务平台
  • 定制网站开发者有权利倒卖吗磁力bt种子搜索
  • 广州网站建设优化aso关键词覆盖优化
  • org.cn的网站备案条件百度全网营销
  • 网站推广服务方案百度推广怎么弄
  • c2c网站怎么做做谷歌推广比较好的公司
  • 哪个网站做兼职北京网站快速优化排名
  • 大连网络推广网站优化找哪家好google优化推广
  • 金坛网站建设山西网络推广
  • 威宁做网站百度收录教程
  • web网站设计的要求互联网广告精准营销
  • 商城购物网站建设方案怎么自己做个网站