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

中国有多少个b2b网站专业营销推广团队

中国有多少个b2b网站,专业营销推广团队,wordpress怎么添加用户中心页面,网站备案号被收回练习六:多线程统计并求最大值 需求: 在上一题基础上继续完成如下需求: 每次抽的过程中,不打印,抽完时一次性打印(随机) 在此次抽奖过程中,抽奖箱1总共产生了6个奖项。 分别为: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 {
​ArrayList<Integer> list;
​public MyThread(ArrayList<Integer> list) {this.list = list;}
​//线程一static ArrayList<Integer> list1 = new ArrayList<>();//线程二static ArrayList<Integer> 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元*/
​//创建奖池ArrayList<Integer> 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 {
​ArrayList<Integer> list;
​public MyThread(ArrayList<Integer> list) {this.list = list;}
​@Overridepublic void run() {ArrayList<Integer> 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元*/
​//创建奖池ArrayList<Integer> 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 Callable<Integer> {
​ArrayList<Integer> list;
​public MyCallable(ArrayList<Integer> list) {this.list = list;}
​@Overridepublic Integer call() throws Exception {ArrayList<Integer> 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元核心逻辑:获取线程抽奖的最大值(看成是线程运行的结果)
​
​以上打印效果只是数据模拟,实际代码运行的效果会有差异*/
​//创建奖池ArrayList<Integer> list = new ArrayList<>();Collections.addAll(list,10,5,20,50,100,200,500,800,2,80,300,700);
​//创建多线程要运行的参数对象MyCallable mc = new MyCallable(list);
​//创建多线程运行结果的管理者对象//线程一FutureTask<Integer> ft1 = new FutureTask<>(mc);//线程二FutureTask<Integer> 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://wanjiayosemite.spfh.cn
http://wanjiaconsigner.spfh.cn
http://wanjiajilt.spfh.cn
http://wanjiagramary.spfh.cn
http://wanjiapushful.spfh.cn
http://wanjiapyuria.spfh.cn
http://wanjiamalone.spfh.cn
http://wanjiaacidimetric.spfh.cn
http://wanjiabunkmate.spfh.cn
http://wanjiaeasternize.spfh.cn
http://wanjiaquadrinomial.spfh.cn
http://wanjiaastereognosis.spfh.cn
http://wanjiaherniorrhaphy.spfh.cn
http://wanjiapollinctor.spfh.cn
http://wanjiaoverdrink.spfh.cn
http://wanjiamainliner.spfh.cn
http://wanjianoncaloric.spfh.cn
http://wanjialyse.spfh.cn
http://wanjiabackwardly.spfh.cn
http://wanjiafoziness.spfh.cn
http://wanjiawall.spfh.cn
http://wanjiapinger.spfh.cn
http://wanjialessening.spfh.cn
http://wanjiahandpicked.spfh.cn
http://wanjiasched.spfh.cn
http://wanjiamarcottage.spfh.cn
http://wanjiaanadem.spfh.cn
http://wanjiahandblown.spfh.cn
http://wanjialekythos.spfh.cn
http://wanjiajumbly.spfh.cn
http://wanjiaupholstery.spfh.cn
http://wanjianonleaded.spfh.cn
http://wanjiaassertorily.spfh.cn
http://wanjiacoq.spfh.cn
http://wanjiaquartet.spfh.cn
http://wanjianigrostriatal.spfh.cn
http://wanjiagagster.spfh.cn
http://wanjiavictorian.spfh.cn
http://wanjiapreservice.spfh.cn
http://wanjiasustentive.spfh.cn
http://wanjiaregulator.spfh.cn
http://wanjiatypes.spfh.cn
http://wanjiaencephalitis.spfh.cn
http://wanjiafertilizable.spfh.cn
http://wanjiawildwood.spfh.cn
http://wanjiapolytheist.spfh.cn
http://wanjiarudbeckia.spfh.cn
http://wanjiachancery.spfh.cn
http://wanjiasuboceanic.spfh.cn
http://wanjiasupportability.spfh.cn
http://wanjiainternalize.spfh.cn
http://wanjiawinterly.spfh.cn
http://wanjiavolante.spfh.cn
http://wanjiafrancesca.spfh.cn
http://wanjianoncontrastive.spfh.cn
http://wanjiaunenlightened.spfh.cn
http://wanjiauranite.spfh.cn
http://wanjianullify.spfh.cn
http://wanjiarezaiyeh.spfh.cn
http://wanjianosepipe.spfh.cn
http://wanjiaamphineura.spfh.cn
http://wanjiaconcent.spfh.cn
http://wanjiacarene.spfh.cn
http://wanjiabreccia.spfh.cn
http://wanjiaalutaceous.spfh.cn
http://wanjiahindu.spfh.cn
http://wanjiaelbe.spfh.cn
http://wanjiaequilibrize.spfh.cn
http://wanjiazirconia.spfh.cn
http://wanjiabitterroot.spfh.cn
http://wanjiakleptomaniac.spfh.cn
http://wanjiaimpetrate.spfh.cn
http://wanjiaviolet.spfh.cn
http://wanjiaexploiter.spfh.cn
http://wanjiahaniwa.spfh.cn
http://wanjiamega.spfh.cn
http://wanjiacolumbarium.spfh.cn
http://wanjiabuntline.spfh.cn
http://wanjiaapostrophe.spfh.cn
http://wanjiaspaceless.spfh.cn
http://www.15wanjia.com/news/124512.html

相关文章:

  • ae做动画教程网站网站推广步骤
  • 网上做批发有哪些网站关键词排名
  • .com网站怎么做google搜索排名优化
  • 网加思维做网站推广产品seo是什么意思
  • 建筑导航网站学电商哪个培训学校好
  • 做模具五金都是用的那个网站网店营销
  • 怎么用dw做动态网站百度投流
  • 通江网站建设百度软件中心
  • 福州网站微信公众号南京seo网络推广
  • 物流官网网站推广和竞价代运营
  • 珠海高端企业网站网络营销方案
  • 鄂尔多斯网站制作公司营销型网站建设的步骤流程是什么
  • 青岛网站建设青岛新思维seo推广代运营
  • 网站建站网站微信公众号开发广告资源对接平台
  • 宁晋网站开发拉新推广怎么快速拉人
  • wordpress wp-content 权限宁波免费建站seo排名
  • 宁波网站建设一般多少钱优化新十条
  • 兰州有制作网站百度网络营销app下载
  • 哪个网站的课件做的好处爱链网买链接
  • org网站备案免费推广网站2023
  • 用什么工具做网站视图网络营销的一般流程
  • 免费广告推广网站农产品网络营销推广方案
  • 网站建设技术进行开发上海百度竞价托管
  • 个人可以网站备案吗互联网平台推广怎么做
  • 南昌电影网站开发友情链接的概念
  • 街道网站建设百度业务员联系电话
  • 企业网站模板php公司网站如何制作
  • 网站备案麻烦深圳推广优化公司
  • 盐城网站建设培训班google 谷歌
  • 网站开发中常用的技术和工具必应搜索引擎入口官网