news 2026/4/23 16:58:47

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

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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); } } }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/23 8:05:35

宿迁泗洪无人机培训公司

宿迁泗洪无人机培训公司&#xff1a;助力行业发展新动力在宿迁泗洪地区&#xff0c;随着无人机应用领域的不断拓展&#xff0c;无人机培训公司正扮演着越来越重要的角色。以翼启飞科技caac执照考证为代表的培训公司&#xff0c;为当地培养了众多优秀的无人机专业人才。培训市场…

作者头像 李华
网站建设 2026/4/23 11:46:25

17、网络服务:邮件与文件传输配置指南

网络服务:邮件与文件传输配置指南 1. NTP 故障排除工具 NTP(网络时间协议)的分发中包含了一些实用的故障排除工具,如 ntptrace 。 jitter 表示系统时钟与远程时钟的观测时间误差(以毫秒为单位),是均方根(RMS)时间差的平均值(在 NTPv4 之前,此列称为 dispersio…

作者头像 李华
网站建设 2026/4/23 14:39:17

Neo4j查询语句写法举例

Neo4j查询语句写法举例 # -*- coding: utf-8 -*- from py2neo import Graph,Node,Relationship,NodeMatcher #版本说明&#xff1a;Py2neo v4 class Neo4j_Handle():graph Nonematcher Nonedef __init__(self):print("Neo4j Init ...")def connectDB(self):self.gr…

作者头像 李华
网站建设 2026/4/23 11:47:53

6、游戏开发中的资源与场景管理及跨设备兼容性处理

游戏开发中的资源与场景管理及跨设备兼容性处理 1. 资源管理 在游戏开发中,资源管理是一项重要任务。以下代码展示了资源管理类中对声音和文件资源的初始化: if (!soundAssets) {soundAssets = [[SoundManager alloc] init]; } if (!fileAssets) {fileAssets = [[FileMan…

作者头像 李华
网站建设 2026/4/22 23:16:12

React 19让你的经验失效了?深入剖析架构巨变背后的真相

上周五晚上10点,我盯着屏幕上的代码陷入了沉思。这是一个再普通不过的用户信息展示组件,props没变,state没变,连useEffect的依赖数组都是空的。但它就是莫名其妙地重新渲染了,而且渲染的时机完全不符合我过去5年积累的React经验。我打开React DevTools,检查了组件树,检查了Prof…

作者头像 李华
网站建设 2026/4/23 13:01:40

Element Plus Notification组件HTML渲染问题的深度诊断与高效修复方案

Element Plus Notification组件HTML渲染问题的深度诊断与高效修复方案 【免费下载链接】element-plus element-plus/element-plus: Element Plus 是一个基于 Vue 3 的组件库&#xff0c;提供了丰富且易于使用的 UI 组件&#xff0c;用于快速搭建企业级桌面和移动端的前端应用。…

作者头像 李华