这道java习题后两个填的代码看不懂啊

这是JAVA多线程编程练习的两道题目!!!求高手解决!!!拜托了!!!_百度知道
这是JAVA多线程编程练习的两道题目!!!求高手解决!!!拜托了!!!
我给你80分
我有更好的答案
环境传感器的数据还没更新呢.01s算的话,100次以后?你这每次读取数据按照0你这三个大气环境数据看过一个对象还是三个对象啊,如果是三个的话是每5s获取其中一个环境数据的值么
就安你理解的意思来就行!!!!
采纳率:36%
e)&nbsp,&nbsp.atmosphere&+&&;AtmosphereSensor(Atmosphere&atmosphere)&static&(Exception&nbsp.5秒/次&{
int&i&读取大气信息&=&&
}&catch&nbsp.nextFloat());
Tvoid&& } public&void&setAtmosphere(Atmosphere&atmosphere)&传感器数据&&&&温度&=&+&&;{
return&atmosphereSComputer(AtmosphereSensor&atmosphereSensor)&nbsp.Rpublic&class&{
Atmosphere&atmosphere&=&atmosphere.getHumidity()&&@author&795829&*&
new&Thread(computer);=&atmosphereSnew&Atmosphere();=&new&{
try&i++&+&{
return&湿度&
atmosphere.setTemperature(new&Random(System.currentTimeMillis()).start();
AtmosphereSensor&=&atmosphereS&*&传感器&new&Computer(atmosphereSensor);atmosphereSensor&AtmosphereSensor(atmosphere);
Computer&computer&=&nbsp.sleep(500);
atmosphere.atmosphereSensor&&{
new&Thread(atmosphereSensor).println(&=&1;
while&(true)&{
Thread.sleep(500);
atmosphere.setHumidity(new&nbsppackage&com.kevin2014.main(String[]&args)&nbsp.getTemperature()& } @Override public&void&run()&Random(S&计算机&2秒/次&读取传感器数据&nbsp.atmosphere&{ public&atmosphere.getWind());=&{
this.atmosphereSensor&nbsp.=&{
} @Override public&void&run()&import&AtmosphereTest& }}/**& public&nbsp.currentTimeMillis()).nextFloat());Atmosphere&*/class&AtmosphereSensor&implements&Runnable&{ private&nbsp.start();&+&atmosphere,&{
this.printStackTrace();*&&*&=&&&+&{
for&(int&i&=&1;&i&&=&50;&i++)&{
Thread.sleep(2000);
System.out.println(i&+&&&计算机数据&&&&温度&=&&&+&atmosphereSensor.getAtmosphere().getTemperature()
+&&,&湿度&=&&&+&atmosphereSensor.getAtmosphere().getHumidity()&+&&,&风速&=&&
+&atmosphereSensor.getAtmosphere().getWind());
}&catch&(Exception&e)&{
e.printStackTrace();
} }}class&Atmosphere&{ private&float& private&float& private&float& public&float&getTemperature()&{
return& } public&void&setTemperature(float&temperature)&{
this.temperature&=& } public&float&getHumidity()&{
return& } public&void&setHumidity(float&humidity)&{
this.humidity&=& } public&float&getWind()&{
return& } public&void&setWind(float&wind)&{
this.wind&=& }};{
*&&*&*/class&Computer&implements&Runnable&{ private&nbsp.nextFloat());
Thread.sleep(500); } public&AtmosphereSensor&getAtmosphereSensor()&1;java.@author&795829&*&
} }}/**&*& } public&void&setAtmosphereSensor(AtmosphereSensor&atmosphereSensor)&AtmosphereSensor&-----&&&+& } public&Atmosphere&getAtmosphere()&nbsp.setWind(new&Random(System.currentTimeMillis());风速&atmosphereS public&nbsp
你来回答“谁知道在百度里面的《Java 多线程编程练习题》最后编程题的两道题的答案!!!”这个提问我把财富给你啊!!!!
//1.import&java.util.ArrayLimport&java.util.Aimport&java.util.Limport&java.util.Rpublic&class&ThroughHole&{ static&Object&hole&=&new&Object(); public&static&void&main(String[]&args)&{
Random&r&=&new&Random();
String[]&names&=&{&&A&,&&B&,&&C&&,&D&,&E&,&F&,&G&,&H&,&H&,&I&};
List&String&&nameList&=&new&ArrayList&String&(Arrays.asList(names));
while&(nameList.size()&&&0)&{
final&String&name&=&nameList.remove(r.nextInt(nameList.size()));
System.out.println(name+&&is&starting&);
new&Thread(new&Runnable()&{
public&void&run()&{
synchronized&(hole)&{
System.out.println(name&+&&:&is&throughing&);
Thread.sleep(5000);
}&catch&(InterruptedException&e)&{
e.printStackTrace();
}).start();
} }}第二题没明白啥意思
第二道就是一个简单的多线程应用程序!思想和第一道差不多!!!拜托你了,只要能基本达到要求都行~~~~
为您推荐:
其他类似问题
多线程编程的相关知识
换一换
回答问题,赢新手礼包JAVA语言I/O输入输出的一个练习题目,我根本看不懂,请帮我做一下,谢谢了,实在感谢 50分!!!_百度知道
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。
JAVA语言I/O输入输出的一个练习题目,我根本看不懂,请帮我做一下,谢谢了,实在感谢 50分!!!
要求代码:打开一个文本文件(读取输入),将文件中的小写字母转为大写,并保存到一个新文本文件中。
我有更好的答案
File aim = new File(& 写入aim文件中
//);/ 针对aim文件 PrintWriter
PrintWriter writer = new PrintWriter(aim);
while (/ 关闭写入器
} catch (IOException e) {
/// 路径可以换:/aim.txt&quot.printStackTrace();/ 文件不存在则新建
if (!aim.exists()) {
aimpublic static void main(String[] args) {
&#47.createNewFile();).println(line).hasNext()) {
/&#47,这里是绝对路径
File src = new File(&d:/ 转换为大写
line = 针对src文件的扫描器
Scanner sca = new Scanner(src);
&#47.close(); 读取一行
String line = sca.nextLine().toUpperCase();source.txt&d
采纳率:70%
readLine());));
if(fw&!=&null)
=&import&nbsp!=&null)
args[])&throws&Exception {
BufferedReader&=&new&nbsp.close();FileWriter(&D:\\b.txt&quot!=null){
fw.write(s.toLowerCase()+&\n&);
fw.flush();
if(br&.FileWpublic&class&
while((s==&new&fw&java.
FileWriter&java.br&FileReader(&D:\\a.txt&quotimport&BufferedReader(new&nbsp.io.FileRTestBaiduKnow&{ public&static&void&main(String&nbsp.BufferedRimport&).close()
本回答被网友采纳
为您推荐:
其他类似问题
java语言的相关知识
换一换
回答问题,赢新手礼包登录以解锁更多InfoQ新功能
获取更新并接收通知
给您喜爱的内容点赞
关注您喜爱的编辑与同行
966,690 十一月 独立访问用户
语言 & 开发
架构 & 设计
文化 & 方法
您目前处于:
简洁Java之道
简洁Java之道
Casimir Saternos
0&他的粉丝
0&他的粉丝
日. 估计阅读时间:
:开启与Netflix、微软、ThoughtWorks等公司的技术创新之路!
亲爱的读者:我们最近添加了一些个人消息定制功能,您只需选择感兴趣的技术主题,即可获取重要资讯的。
Author Contacted
语言 & 开发
117 他的粉丝
函数式编程
11 他的粉丝
1844 他的粉丝
相关厂商内容
相关赞助商
告诉我们您的想法
允许的HTML标签: a,b,br,blockquote,i,li,pre,u,ul,p
当有人回复此评论时请E-mail通知我
允许的HTML标签: a,b,br,blockquote,i,li,pre,u,ul,p
当有人回复此评论时请E-mail通知我
允许的HTML标签: a,b,br,blockquote,i,li,pre,u,ul,p
当有人回复此评论时请E-mail通知我
赞助商链接
InfoQ每周精要
订阅InfoQ每周精要,加入拥有25万多名资深开发者的庞大技术社区。
架构 & 设计
文化 & 方法
<及所有内容,版权所有 &#169;
C4Media Inc.
服务器由 提供, 我们最信赖的ISP伙伴。
北京创新网媒广告有限公司
京ICP备号-7
找回密码....
InfoQ账号使用的E-mail
关注你最喜爱的话题和作者
快速浏览网站内你所感兴趣话题的精选内容。
内容自由定制
选择想要阅读的主题和喜爱的作者定制自己的新闻源。
设置通知机制以获取内容更新对您而言是否重要
注意:如果要修改您的邮箱,我们将会发送确认邮件到您原来的邮箱。
使用现有的公司名称
修改公司名称为:
公司性质:
使用现有的公司性质
修改公司性质为:
使用现有的公司规模
修改公司规模为:
使用现在的国家
使用现在的省份
Subscribe to our newsletter?
Subscribe to our industry email notices?
我们发现您在使用ad blocker。
我们理解您使用ad blocker的初衷,但为了保证InfoQ能够继续以免费方式为您服务,我们需要您的支持。InfoQ绝不会在未经您许可的情况下将您的数据提供给第三方。我们仅将其用于向读者发送相关广告内容。请您将InfoQ添加至白名单,感谢您的理解与支持。您的位置:&&推荐的文章
java程序求解,望各位帮忙小弟解决一道习题,谢谢啦!
java程序求解,望各位帮忙小弟解决一道习题,谢谢啦!
继承Thread类定义线程类A,计算并输出1—1000内的所有素数,继承Thread类定义线程类B,输出.9之间的随机浮点数。创建A和B的对象,并让这两个对象交替运行。
[&+getName()+&quot.util.List,输出.9之间的随机浮点数。 * 创建A和B的对象,并让这两个对象交替运行。 * &= n) {
while (i &(50);
for (i = 2;
B b = new B(););p& *
* @author: zhangqiang * @+getName()+&]&quot.get(i))
ret.add(i); i&
int k = 2 *import java.get(i)) {
ret.add(i).println(&quot.start().set(i);
while (i * i & i &= i++)
b.util.BitS
} }}class B extends Thread { @Override public void run() {
Random ran = new Random().
for(int r : ret){
System.out.println(&[&quot,计算并输出1—1000内的所有素数;
BitSet bs = new BitSet(n + 1);
System.9: Dec 1, 2010 * &&#47;);
b.setName(&Thread-A&quot: Ver 1.0 *&#47;public class BaiduHelper { public static void main(String[] args) throws InterruptedException {
A a = new A(); * 时间.ArrayL * &p&1000; ++i){
double ret = ran.nextDouble()*0,
* 继承Thread类定义线程类B;
for(int i=0;
a.util.R+r);&#47;** * &
while (k &= n) {
bs.clear(k);= n) {
if (bs.setName(&p& * 继承Thread类定义线程类A;Integer& ret = new ArrayList&Integer& }}class A extends Thread { @Override public void run() {
int n = 1000.start();Thread-B&&#47;p&gtimport java.util...
getPrime(){List&}public boolean isPrime(int n){if(n &lt.printStackTrace();for(int i = 3;=100; i++){float n =this.count =}@Overridepublic void run() {synchronized (count) {Random random = new Random();for (int i = 1.sleep(1000);}}}}}public class RandomThread extends Thread {Vpublic RandomThread(String name, Value count) {super(name).printStackTrace().start();if (count.wait();} catch (InterruptedException e) {e.printStackTrace();}}try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}}}}}public class Value {public void add() {count++;} else {try {count.wait().add().getName() + &Integer& primeList = new ArrayList&&(); + n);Integer& primeList = getPrime();synchronized (count) {for (Integer n : primeList){if (count.count % 2 == 0) {System.out.println(T i*i &= i += 2)if(n%i == 0)}@Overridepublic void run() {List&if(n%2==0) return falsepublic class PrimeThread extends Thread {V} catch (InterruptedException e) {e;&quot.currentThread();this.count =}public List&Integer& 2)if(n == 2)this.count =}@Overridepublic String toString() {return count + & --- & + n);count.add();count.notify();}public Value(int count) {super();public PrimeThread(String name, Value count) {super(name), val).add(i);}......
import java.util.ArrayL import java.util.BitSe...
以下是JLS(Java Language Specification)中对while的定义 Whil...
好的,加你了
第一二个没看懂你意思, 第3: Scanner sc = new Scanner(System.in...
构造方法中窗体属性设置错了 f.setVisible(true); f.setSize(400,30...
呵呵,确实无聊,不过学习还是必须的。代码如下: public class TestDays { pu...
//可以转换大小写 import javax.swing.JOptionP public c...
自己的作业自己做。
一道JAVA程序题,希望好心者帮忙解决,谢谢。最好是面向对象... 1
你Char.java文件保存的编码格式和你系统默认的编码格式不一致.你的文本编辑保存时应该是UTF-...
购物网站热门产品排行java90道练习题_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
java90道练习题
阅读已结束,下载文档到电脑
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩4页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢

我要回帖

 

随机推荐