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

SDUT java 常用类(日期数学 封装类 随机数)

7-1 sdut-常用类-骄傲的代价

import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); while(n-->0) { BigInteger a=new BigInteger(sc.next()); BigInteger b=new BigInteger(sc.next()); System.out.println(a+"+"+b+"="+a.add(b)); System.out.println(a+"-"+b+"="+a.subtract(b)); System.out.println(a+"*"+b+"="+a.multiply(b)); System.out.println(a+"/"+b+"="+(a.divide(b))); System.out.println(a+"%"+b+"="+a.mod(b)); } } }

7-2 jmu-Java-02-使用逐步逼近法求开根号

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { double x = sc.nextDouble(); double sum=0; if(x<0) System.out.println("NaN"); else{ while(sum*sum<x&&Math.abs(x-sum*sum)>0.0001) { sum+=0.0001; } System.out.printf("%.6f\n",sum); } } } }

7-3 伪随机数

import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int k=sc.nextInt(); Random random=new Random(k); int x=0; for(int i=0;i<n;i++) { x=random.nextInt(m); } System.out.println(x); } }

7-4 jmu-java-随机数-使用蒙特卡罗法计算圆周率的值

import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long seed = sc.nextLong(); int n = sc.nextInt(); int count=0; Random r=new Random(seed); for(int i=0;i<n;i++) { double x=r.nextDouble()*2-1; double y=r.nextDouble()*2-1; if(x*x+y*y<=1) count++; } System.out.println(4*(double)count/n); } }

7-5 jmu-Java-01入门-取数字浮点数

import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { String s = sc.nextLine(); char[] chars=s.toCharArray(); int len=s.length(); int count=0; for(int i=0;i<len;i++) { Character c=chars[i]; if(Character.isDigit(c)) count+=(c-'0'); } System.out.println(count); } } }

7-6 那年有几个黑五?

public class Main { public static void main(String[] args) { System.out.println("2"); } }

7-7 无聊的小明来数1

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); while (n-->0) { int x=sc.nextInt(); int y; int count=0; while(x!=0) { y=x%2; if(y==1) count++; x/=2; } System.out.println(count); } } }
http://www.cnnetsun.cn/news/83383.html

相关文章:

  • 毕业即就业!网络安全专业大学生必备的5大核心技能与实战指南
  • 知名外资对冲基金新需求:- QD/QR:HK,同业,有机器学习特别是深度学习方向经验的人选- Production Reliability Engineer:即SRE Operation部门的P
  • 12、游戏开发:用户界面与人工智能实现
  • 申请专利带来的好处
  • BilibiliSponsorBlock智能配置:一键告别B站广告干扰
  • 单细胞T细胞分析新突破:高效追踪免疫应答全流程
  • PDF补丁丁终极使用指南:PDFPatcher快速精通手册
  • 35、GnomeVFS 文件传输、类型识别与 URI 操作全解析
  • mysql修改密码
  • Git commit规范与TensorFlow项目协作开发的最佳实践
  • CVE-2025-55182和CVE-2025-66478漏洞(Next.js)
  • CRMEB-PHP商品采集模块开发指南:API对接与批量上架实现
  • 基于django微信小程序的校园食堂点餐订餐系统
  • LangFlow工作流引擎在多模态大模型中的调度作用
  • 32、开源系统在不同领域的高效应用案例剖析
  • VeraCrypt终极指南:5分钟掌握磁盘加密完整流程
  • ENSP抓包分析GPT-SoVITS API通信数据格式
  • 37、Solaris 文件与文件 I/O 深入解析
  • 45、内核可调参数、开关和限制及虚拟地址映射详解
  • AI市场舆情分析与量化风险:超越预测的2025年AI决策之道
  • Ivy统一AI框架:5步实现多框架代码无缝转换
  • Socket.IO-Client-Swift完整开发指南:从零构建实时iOS应用
  • LangFlow工作流导出为API接口的完整流程
  • 25、Linux 系统通信指南:网络连接、传真与调制解调器使用
  • 22、Linux系统中的提醒工具使用指南
  • 加密已死?不,它正在重生:为什么加密仍然是数据安全的终极堡垒
  • 【SS拓扑】基于移相控制的磁耦合谐振无线电能传输系统仿真附Simulink仿真
  • 26、负载均衡与高可用集群搭建指南
  • 告别单一工具化思维:如何构建覆盖全生命周期的零工管理体系?
  • 27、高可用性集群中ldirectord的配置与使用指南