
java语法错误,进行分析时已经到达文件结尾
classRes{privateStringname;privateStringsex;privatebooleanflag=false;publicsynchroniz...
class Res
{
private String name;
private String sex;
private boolean flag=false;
public synchronized void set(String name,String sex)
{
if(flag)
try{this.wait();}catch (Exception e){}
this.name=name;
this.sex=sex;
flag=true;
this.notify();
}
public synchronized void out()
{
if(!flag)
try{this.wait();}catch (Exception e){}
System.out.println(name+"........"+sex);
flag=false;
this.notify();
}
}
class Input implements Runnable
{
private Res r;
Input(Res r)
{
this.r=r;
}
public void run()
{
int x=0;
while(true)
{
if(x==0)
r.set("mike","man");
else
r.set("丽丽","女女女女女");
x=(x+1)%2;
}
}
class Output implements Runnable
{
private Res r;
Output(Res r)
{
this.r=r;
}
public void run()
{
while(true)
{
r.out();
}
}
}
class haha
{
public static void main(String[] args)
{
Res r=new Res();
Input in=newInput(r);
Output out=newOutput(r);
Thread t1=new Thread(in);
Thread t2=new Thread(out);
t1.start();
t2.start();
}
}
他在我代码的最后面提示错误说到达文件结尾,代码最后是到达结尾没错,干嘛提示错误 展开
{
private String name;
private String sex;
private boolean flag=false;
public synchronized void set(String name,String sex)
{
if(flag)
try{this.wait();}catch (Exception e){}
this.name=name;
this.sex=sex;
flag=true;
this.notify();
}
public synchronized void out()
{
if(!flag)
try{this.wait();}catch (Exception e){}
System.out.println(name+"........"+sex);
flag=false;
this.notify();
}
}
class Input implements Runnable
{
private Res r;
Input(Res r)
{
this.r=r;
}
public void run()
{
int x=0;
while(true)
{
if(x==0)
r.set("mike","man");
else
r.set("丽丽","女女女女女");
x=(x+1)%2;
}
}
class Output implements Runnable
{
private Res r;
Output(Res r)
{
this.r=r;
}
public void run()
{
while(true)
{
r.out();
}
}
}
class haha
{
public static void main(String[] args)
{
Res r=new Res();
Input in=newInput(r);
Output out=newOutput(r);
Thread t1=new Thread(in);
Thread t2=new Thread(out);
t1.start();
t2.start();
}
}
他在我代码的最后面提示错误说到达文件结尾,代码最后是到达结尾没错,干嘛提示错误 展开
6个回答
展开全部
原因:
分析已达到文件结尾一般是括号没有闭合,或者缺少了分号
解决方案:
手工查看括号闭合情况
使用带自动对齐功能的编辑器如eclipse,notepad++
建议平时编程时多注意积累错误经验,语法错误不应当耗费太多时间
拓展资料:
Java的组成:
Java编程语言
Java类文件格式
Java虚拟机
Java应用程序接口
当编辑并运行一个Java程序时,需要同时涉及到这四种方面。使用文字编辑软件(例如记事本、写字板、UltraEdit等)或集成开发环境(Eclipse、MyEclipse等)在Java源文件中定义不同的类 ,通过调用类(这些类实现了Java API)中的方法来访问资源系统,
把源文件编译生成一种二进制中间码,存储在class文件中,然后再通过运行与操作系统平台环境相对应的Java虚拟机来运行class文件,执行编译产生的字节码,调用class文件中实现的方法来满足程序的Java API调用
参考资料:百度百科_Java
展开全部
(1) 原因
分析已达到文件结尾一般是括号没有闭合,或者缺少了分号
(2) 解决方案
1.手工查看括号闭合情况
2.使用带自动对齐功能的编辑器如eclipse,notepad++
(3) 建议平时编程时多注意积累错误经验,语法错误不应当耗费太多时间
(4) 参考资料:无
分析已达到文件结尾一般是括号没有闭合,或者缺少了分号
(2) 解决方案
1.手工查看括号闭合情况
2.使用带自动对齐功能的编辑器如eclipse,notepad++
(3) 建议平时编程时多注意积累错误经验,语法错误不应当耗费太多时间
(4) 参考资料:无
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//括号没有配对,这类错误都是没有配对的结果,请你检查这一段:
class Input implements Runnable
{
private Res r;
Input(Res r)
{
this.r=r;
}
public void run()
{
int x=0;
while(true)
{
if(x==0)
r.set("mike","man");
else
r.set("丽丽","女女女女女");
x=(x+1)%2;
}
}
//你的run()方法有开始的括号,没有结束的括号。。。或者说你的Input类没有结束的括号。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已修改
class haha
{
private String name;
private String sex;
private boolean flag = false;
public static void main ( String[] args )
{
haha r = new haha ();
Input in = new Input (r);
Output out = new Output (r);
Thread t1 = new Thread (in);
Thread t2 = new Thread (out);
t1.start ();
t2.start ();
}
public synchronized void set ( String name, String sex )
{
if (flag)
try
{
this.wait ();
}
catch (Exception e)
{}
this.name = name;
this.sex = sex;
flag = true;
this.notify ();
}
public synchronized void out ()
{
if (!flag)
try
{
this.wait ();
}
catch (Exception e)
{}
System.out.println (name + "........" + sex);
flag = false;
this.notify ();
}
}
class Input implements Runnable
{
private haha r;
Input ( haha r )
{
this.r = r;
}
public void run ()
{
int x = 0;
while (true)
{
if (x == 0)
r.set ("mike", "man");
else
r.set ("丽丽", "女女女女女");
x = ( x + 1 ) % 2;
}
}
}
class Output implements Runnable
{
private haha r;
Output ( haha r )
{
this.r = r;
}
public void run ()
{
while (true)
{
r.out ();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询