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

网站建设规划书范文5000字阿里云服务器ip做网站

网站建设规划书范文5000字,阿里云服务器ip做网站,海外短视频软件,整合营销的四个层次练习六#xff1a;多线程统计并求最大值 需求#xff1a; 在上一题基础上继续完成如下需求#xff1a; 每次抽的过程中#xff0c;不打印#xff0c;抽完时一次性打印(随机) 在此次抽奖过程中#xff0c;抽奖箱1总共产生了6个奖项。 分别为#xff1a;10,20,100,50…练习六多线程统计并求最大值 需求 在上一题基础上继续完成如下需求 每次抽的过程中不打印抽完时一次性打印(随机) 在此次抽奖过程中抽奖箱1总共产生了6个奖项。 分别为10,20,100,500,2,300最高奖项为300元总计额为932元 在此次抽奖过程中抽奖箱2总共产生了6个奖项。 分别为5,50,200,800,80,700最高奖项为800元总计额为1835元 解决方案一 public class MyThread extends Thread { ​ArrayListInteger list; ​public MyThread(ArrayListInteger list) {this.list list;} ​//线程一static ArrayListInteger list1 new ArrayList();//线程二static ArrayListInteger list2 new ArrayList(); ​Overridepublic void run() {while (true) {synchronized (MyThread.class) {if (list.size() 0) {if(抽奖箱1.equals(getName())){System.out.println(抽奖箱1 list1);}else {System.out.println(抽奖箱2 list2);}break;} else {//继续抽奖Collections.shuffle(list);int prize list.remove(0);if(抽奖箱1.equals(getName())){list1.add(prize);}else {list2.add(prize);}}}try {Thread.sleep(10);} catch (InterruptedException e) {e.printStackTrace();} ​}} } ​ public class Test {public static void main(String[] args) {/*有一个抽奖池,该抽奖池中存放了奖励的金额,该抽奖池中的奖项为 {10,5,20,50,100,200,500,800,2,80,300,700};创建两个抽奖箱(线程)设置线程名称分别为“抽奖箱1”“抽奖箱2”随机从抽奖池中获取奖项元素并打印在控制台上,格式如下:每次抽的过程中不打印抽完时一次性打印(随机)   在此次抽奖过程中抽奖箱1总共产生了6个奖项。分别为10,20,100,500,2,300最高奖项为300元总计额为932元在此次抽奖过程中抽奖箱2总共产生了6个奖项。分别为5,50,200,800,80,700最高奖项为800元总计额为1835元*/ ​//创建奖池ArrayListInteger list new ArrayList();Collections.addAll(list,10,5,20,50,100,200,500,800,2,80,300,700); ​//创建线程MyThread t1 new MyThread(list);MyThread t2 new MyThread(list); ​//设置名字t1.setName(抽奖箱1);t2.setName(抽奖箱2); ​//启动线程t1.start();t2.start();} } ​ 解决方案二 public class MyThread extends Thread { ​ArrayListInteger list; ​public MyThread(ArrayListInteger list) {this.list list;} ​Overridepublic void run() {ArrayListInteger boxList new ArrayList();//1 //2while (true) {synchronized (MyThread.class) {if (list.size() 0) {System.out.println(getName() boxList);break;} else {//继续抽奖Collections.shuffle(list);int prize list.remove(0);boxList.add(prize);}}try {Thread.sleep(10);} catch (InterruptedException e) {e.printStackTrace();} ​}} } ​ public class Test {public static void main(String[] args) {/*有一个抽奖池,该抽奖池中存放了奖励的金额,该抽奖池中的奖项为 {10,5,20,50,100,200,500,800,2,80,300,700};创建两个抽奖箱(线程)设置线程名称分别为“抽奖箱1”“抽奖箱2”随机从抽奖池中获取奖项元素并打印在控制台上,格式如下:每次抽的过程中不打印抽完时一次性打印(随机)   在此次抽奖过程中抽奖箱1总共产生了6个奖项。分别为10,20,100,500,2,300最高奖项为300元总计额为932元在此次抽奖过程中抽奖箱2总共产生了6个奖项。分别为5,50,200,800,80,700最高奖项为800元总计额为1835元*/ ​//创建奖池ArrayListInteger list new ArrayList();Collections.addAll(list,10,5,20,50,100,200,500,800,2,80,300,700); ​//创建线程MyThread t1 new MyThread(list);MyThread t2 new MyThread(list); ​ ​//设置名字t1.setName(抽奖箱1);t2.setName(抽奖箱2); ​ ​//启动线程t1.start();t2.start(); ​} } 练习七多线程之间的比较 需求 在上一题基础上继续完成如下需求 在此次抽奖过程中抽奖箱1总共产生了6个奖项分别为10,20,100,500,2,300 最高奖项为300元总计额为932元 在此次抽奖过程中抽奖箱2总共产生了6个奖项分别为5,50,200,800,80,700 最高奖项为800元总计额为1835元 在此次抽奖过程中,抽奖箱2中产生了最大奖项,该奖项金额为800元 以上打印效果只是数据模拟,实际代码运行的效果会有差异 public class MyCallable implements CallableInteger { ​ArrayListInteger list; ​public MyCallable(ArrayListInteger list) {this.list list;} ​Overridepublic Integer call() throws Exception {ArrayListInteger boxList new ArrayList();//1 //2while (true) {synchronized (MyCallable.class) {if (list.size() 0) {System.out.println(Thread.currentThread().getName() boxList);break;} else {//继续抽奖Collections.shuffle(list);int prize list.remove(0);boxList.add(prize);}}Thread.sleep(10);}//把集合中的最大值返回if(boxList.size() 0){return null;}else{return Collections.max(boxList);}} } ​ package com.itheima.test7; ​ import java.util.ArrayList; import java.util.Collections; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; ​ public class Test {public static void main(String[] args) throws ExecutionException, InterruptedException {/*有一个抽奖池,该抽奖池中存放了奖励的金额,该抽奖池中的奖项为 {10,5,20,50,100,200,500,800,2,80,300,700};创建两个抽奖箱(线程)设置线程名称分别为   抽奖箱1, 抽奖箱2随机从抽奖池中获取奖项元素并打印在控制台上,格式如下: ​在此次抽奖过程中抽奖箱1总共产生了6个奖项分别为10,20,100,500,2,300最高奖项为300元总计额为932元 ​在此次抽奖过程中抽奖箱2总共产生了6个奖项分别为5,50,200,800,80,700最高奖项为800元总计额为1835元 ​在此次抽奖过程中,抽奖箱2中产生了最大奖项,该奖项金额为800元核心逻辑获取线程抽奖的最大值看成是线程运行的结果 ​ ​以上打印效果只是数据模拟,实际代码运行的效果会有差异*/ ​//创建奖池ArrayListInteger list new ArrayList();Collections.addAll(list,10,5,20,50,100,200,500,800,2,80,300,700); ​//创建多线程要运行的参数对象MyCallable mc new MyCallable(list); ​//创建多线程运行结果的管理者对象//线程一FutureTaskInteger ft1 new FutureTask(mc);//线程二FutureTaskInteger ft2 new FutureTask(mc); ​//创建线程对象Thread t1 new Thread(ft1);Thread t2 new Thread(ft2); ​//设置名字t1.setName(抽奖箱1);t2.setName(抽奖箱2); ​//开启线程t1.start();t2.start(); ​ ​Integer max1 ft1.get();Integer max2 ft2.get(); ​System.out.println(max1);System.out.println(max2); ​//在此次抽奖过程中,抽奖箱2中产生了最大奖项,该奖项金额为800元if(max1 null){System.out.println(在此次抽奖过程中,抽奖箱2中产生了最大奖项,该奖项金额为max2元);}else if(max2 null){System.out.println(在此次抽奖过程中,抽奖箱1中产生了最大奖项,该奖项金额为max1元);}else if(max1 max2){System.out.println(在此次抽奖过程中,抽奖箱1中产生了最大奖项,该奖项金额为max1元);}else if(max1 max2){System.out.println(在此次抽奖过程中,抽奖箱2中产生了最大奖项,该奖项金额为max2元);}else{System.out.println(两者的最大奖项是一样的);}} }
http://www.hkea.cn/news/14278498/

相关文章:

  • 在阿里云服务器做淘客网站企查查怎么精准找客户
  • ui的设计网站多媒体教学网站开发的一般步骤
  • 做网站组服务器查icp备案是什么网站
  • 自己网站建设丰台网站建设
  • 潍坊网站建设报价任丘建设网站制作
  • 摄影网站开发背景班级网站模板素材
  • 网站后台管理 ftp网站 建设方案
  • 烟台住房和城乡建设局网站创建wordpress博客
  • 营销网站定制一条龙网站建设哪家好
  • 网站竞价推广做响应式网站的物流
  • 网站首页布局风格wordpress支付宝红包
  • 桂城网站建设制作wordpress当前网址参数
  • 无锡做网站无锡网站设计怎样学网络推广
  • 发展速度迅猛 具有丰富的网站建设经验南昌seo管理
  • 公积金网站怎么做增员软文营销文章
  • 网站排名优化工薪待遇微营销平台
  • 沙县住房和城乡规划建设局网站专业直播网站开发
  • 重庆网站备案大厅开公司一年需要多少费用
  • 营销型网站建设范文免费找答案的网站
  • 南通营销平台网站建设做网站打印费复印费清单
  • 代理服务网站网站建设氺首选金手指12
  • 电商网站开发的职责wordpress 本地建站教程
  • 台州的网站建设电商网站建设网络公司
  • php 企业网站系统下载网站域名的管理密码如何索取
  • 网站盈利的10种方式新的网站怎么推广
  • 旅游网站建设启动方案dxc采集wordpress插件
  • 在iis里面创建网站秦皇岛住建部官网
  • 漳州网站建设选博大不错设计家装的软件
  • 网站外链是友情连接吗关键词怎么找出来
  • 网站制作与建设在线视频播放网站开发