云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 七种方法求水仙花数

七种方法求水仙花数

  • 62 次阅读
  • 3 次下载
  • 2025/5/4 7:49:18

______ 水仙花数

1.4.3 遇到的问题及解决方案 后果

分析

环境配置错误,在配置MPI的环境时花了很多时间,在自己电脑上运行一直出错,后来在机房运行成功的。

1.5 基于Java(Runnable)的并行算法实现 1.5.1 代码及注释(变量名 名字首字母 开头)

import java.lang.Thread;

public class JavaThread extends Thread {

private int start; private int end;

______ 水仙花数

private int sum=0;

public JavaThread(int start,int end) {

super();

this.start=start; this.end=end; }

public void run()//并行函数 {

int a,b,c;

for(int xlh=start;xlh<=end;xlh+=2) {

a=xlh/100; b=(xlh-a*100)/10; c=xlh; try { sleep(1);

} catch (InterruptedException e) { e.printStackTrace(); }

if(a*a*a+b*b*b+c*c*c==xlh&&xlh>100&&xlh<1000) { sum++;

System.out.println(xlh);

______ 水仙花数

} } }

public int Flower() throws InterruptedException//串行函数 {

int a,b,c; sum=0;

for(int xlh=start;xlh<=end;xlh++)//求水仙花数 {

a=xlh/100; b=(xlh-a*100)/10; c=xlh; sleep(1);

if(a*a*a+b*b*b+c*c*c==xlh&&xlh>100&&xlh<1000) { sum++;

System.out.println(xlh); } }

return sum; }

public int getSum() {

______ 水仙花数

return sum; }

public static void main(String []args)throwsInterruptedException {

JavaThread thread1=new JavaThread(1,1000);//确定开始以及结束值 JavaThread thread2=new JavaThread(2,1000); System.out.println(\并行结果:\);

long startTime=System.currentTimeMillis();//并行开始 thread1.start(); thread2.start(); thread1.join(); thread2.join();

long endTime=System.currentTimeMillis();

System.out.println(\并行时间:\+(endTime-startTime)); double t1=endTime-startTime;

startTime=System.currentTimeMillis();//并行结束

System.out.println(\串行结果:\);

JavaThread thread=new JavaThread(1,1000); thread.Flower();

endTime=System.currentTimeMillis();

System.out.println(\串行时间:\+(endTime-startTime)); double t2=endTime-startTime; System.out.println(\加速比\+t2/t1);

搜索更多关于: 七种方法求水仙花数 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

______ 水仙花数 1.4.3 遇到的问题及解决方案 后果 分析 环境配置错误,在配置MPI的环境时花了很多时间,在自己电脑上运行一直出错,后来在机房运行成功的。 1.5 基于Java(Runnable)的并行算法实现 1.5.1 代码及注释(变量名 名字首字母 开头) import java.lang.Thread; public class JavaThread extends Thread { private int start; private int end; ______ 水仙花数 private int sum=0; public Java

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com