收藏 分销(赏)

验证任意一个大于2的偶数都能分解成两个素数之和代码.doc

上传人:pc****0 文档编号:7197966 上传时间:2024-12-27 格式:DOC 页数:6 大小:400KB 下载积分:10 金币
下载 相关 举报
验证任意一个大于2的偶数都能分解成两个素数之和代码.doc_第1页
第1页 / 共6页
验证任意一个大于2的偶数都能分解成两个素数之和代码.doc_第2页
第2页 / 共6页


点击查看更多>>
资源描述
计算机科学与技术学院实验报告   实验题目:验证任意一个大于2的偶数都能分解成两个素数之和。 学号: 日期:2014-10-23 班级:电子商务2014级 姓名: Email: 实验目的: 服务器端的对象负责对是否是素数进行判断。 客户端负责验证一定范围内的猜想。 服务器端可以定时查询客户端验证的进度。 硬件环境:机房电脑  软件环境:JDK6,Eclipse,RMI插件包 实验步骤: 1.Prime.java import java.rmi.*; // RMI 本地接口必须从Remote 接口派生 public interface Prime extends Remote { // 接口中的具体方法声明,注意必须声明抛出RemoteException boolean isPrime(int n) throws RemoteException; void setStart(int n) throws RemoteException; void setEnd(int n) throws RemoteException; void setNow(int n) throws RemoteException; } 2.PrimeClient.java import java.rmi.*; import java.util.Arrays; import javax.rmi.PortableRemoteObject; public class PrimeImpl extends PortableRemoteObject implements Prime { private int start = 0, end = 0, now = -1; /* * 构造函数 */ public PrimeImpl() throws RemoteException { super(); } public boolean isPrime(int n) throws RemoteException { int i,c; i=n; boolean b=true; for(c=2;c<=Math.sqrt(i);c++){ if(i%c==0){ b=false; break; } } return b; } public void setStart(int n) throws RemoteException { start = n; } public void setEnd(int n) throws RemoteException { end = n; } public void setNow(int n) throws RemoteException { now = n; } public int getProcess() { if(now == -1 || end == start) return -1; return (now - start) * 100 / (end - start); } } 3.PrimeImpl.java import java.rmi.*; import java.util.Arrays; import javax.rmi.PortableRemoteObject; public class PrimeImpl extends PortableRemoteObject implements Prime { private int start = 0, end = 0, now = -1; /* * 构造函数 */ public PrimeImpl() throws RemoteException { super(); } public boolean isPrime(int n) throws RemoteException { int i,c; i=n; boolean b=true; for(c=2;c<=Math.sqrt(i);c++){ if(i%c==0){ b=false; break; } } return b; } public void setStart(int n) throws RemoteException { start = n; } public void setEnd(int n) throws RemoteException { end = n; } public void setNow(int n) throws RemoteException { now = n; } public int getProcess() { if(now == -1 || end == start) return -1; return (now - start) * 100 / (end - start); } } 4.PrimeServer.java import java.rmi.*; import java.util.Timer; import java.util.TimerTask; public class PrimeServer { public static void main(String[] args) { new PrimeServer().main2(args); } public void main2(String[] args) { // 在服务器端设置安全机制 /* * if (System.getSecurityManager() == null) { * System.setSecurityManager(new RMISecurityManager()); } */ try { System.out.println("开始RMI Server ..."); /* * 创建远程对象的实现实例 */ PrimeImpl hImpl = new PrimeImpl(); System.out.println("将实例注册到专有的URL "); Naming.rebind("PrimeServer", hImpl); System.out.println("等待RMI 客户端调用..."); System.out.println(""); Timer t = new Timer(); t.schedule(new PrimeServer.getProcess(hImpl), 0, 100); } catch (Exception e) { System.out.println("错误: " + e); } } private class getProcess extends TimerTask { private PrimeImpl hImpl; public getProcess(PrimeImpl o) { hImpl = o; } public void run() { int p = hImpl.getProcess(); if(p >= 0) System.out.println("当前查询进度:" + p + "%"); } } } 实验结果截图: 结论分析与体会: 总体来讲实现了要求, 对RMI的机制有了进一步的了解。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服