class a
{
int length;
int line[]=new int[9];
public synchronized void write(int n)
{
while (this.length<9)
line[this.length]=n;
}
public synchronized int read()
{ int m=0;
while (this.length>0)
m=line[this.length];
return m;
}
}
public class aa
{
public static void main(String args[])
{
int q;
a mmm=new a();
mmm.write(2);
q=mmm.read();
System.out.print(q);
}
}
编译能通过,但是没有结果,为什么?
{
int length;
int line[]=new int[9];
public synchronized void write(int n)
{
while (this.length<9)
line[this.length]=n;
}
public synchronized int read()
{ int m=0;
while (this.length>0)
m=line[this.length];
return m;
}
}
public class aa
{
public static void main(String args[])
{
int q;
a mmm=new a();
mmm.write(2);
q=mmm.read();
System.out.print(q);
}
}
编译能通过,但是没有结果,为什么?
解决方案 »
- javaMail的问题!
- 关于ArrayList集合放对方,然后怎么测算出其内存大小呢
- 插入数据库问题!!
- JFTP.jar的问题
- 问一个最简单的问题,一时间想不起来啦。
- DispatchMapping[/myStruts] does not define a handler property
- 想做一个拷贝TextArea的内容到c://a.txt的例子(GUI),有错,进来看一下?
- 简单问题,大家帮忙看一下
- 请教一个Java类的问题
- 在java applete中如何与SQL SERVER数据库连接,并读取数据
- 有关Java的一个小问题!在线等候!getSource()?
- JBuilder9,有两个窗体通信
改称if就跟原代码的目的不同了……
楼主看看你的CPU使用率,肯定是100%
改代码如下看看:
public synchronized void write(int n)
{
length=0;
while (this.length<9)
{
line[this.length]=n;
this.length++;
}
}
read方法看你要实现什么功能再改吧