麻烦看看哪里有问题
package com.imooc.test;
class weather {
private int temperature;
private int humidity;
boolean flage = false;
@Override
public String toString() {
return "温度:" + this.temperature + "湿度" + this.humidity;
}
public int getTemperature() {
return temperature;
}
public void setTemperature() {
this.temperature = (int) (Math.random() * 40);
}
public int getHumidity() {
return humidity;
}
public void setHumidity() {
this.humidity = (int) (Math.random() * 100);
}
public synchronized void setter() {
if (flage) {
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
this.setHumidity();
this.setTemperature();
System.out.println("生成的数据为" + this.toString());
flage = true;
notifyAll();
}
public synchronized void getter() {
if (!flage) {
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
this.setHumidity();
this.setTemperature();
System.out.println("得到的数据为" + this.toString());
flage = false;
notifyAll();
}
class Seweather implements Runnable {
weather wea;
public Seweather(weather wea) {
this.wea = wea;
}
@Override
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i < 100; i++) {
wea.setter();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class Geweather implements Runnable {
weather wea;
public Geweather(weather wea) {
this.wea = wea;
}
@Override
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i < 100; i++) {
wea.getter();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public class Paractice5_3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
weather wea = new weather();
new Thread(new Seweather(wea)).start();
new Thread(new Geweather(wea)).start();
}
}
错误: 找不到或无法加载主类 com.imooc.test.Paractice5_3
原因: java.lang.ClassNotFoundException: com.imooc.test.Paractice5_3
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星