| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2387 人关注过本帖
标题:求助.class'expected是什么错误
只看楼主 加入收藏
sizki
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-9-14
收藏
 问题点数:0 回复次数:13 
求助.class'expected是什么错误

编一个单链表的删除,查找,添加到尾部的程序遇到报错

import java.io.*;

class intsllnode{
public int info;
public intsllnode next;
public intsllnode (int i) {
this (i,null);
}
public intsllnode (int i,intsllnode n) {
info=i;next=n;
}
}
public class intsllist{
protected intsllnode head,tail;
private int input;
private BufferedReader buffer = new BufferedReader(
new InputStreamReader(System.in));
public intsllist() {
head=tail=null;
}

public boolean isempty() {
return head==null;
}

public void printall(){
for (intsllnode tmp=head;
tmp!=null;
tmp=tmp.next )
System.out.print(tmp.info+"");
}

public void delete (int el){
el=getint("I want delete this num");
if(head!=null)
if (el==head.info)
head=head.next;
else{
intsllnode pred=head,tmp=head.next;
for(;tmp!=null&&el!=tmp.info;
pred=pred.next,tmp=tmp=tmp.next)
if (tmp!=null)
pred.next=tmp.next;
}
}
public int find(int el){
el=getint("find this num");
intsllnode tmp=head;
for (;tmp!=null&&el!=tmp.info;
tmp=tmp.next)
if (tmp==null)
return null;
else return tmp.info;
}
public void addtotail(int el){
el=getint("insert a num");
if (!isempty()){
tail.next=new intsllnode(el);
tail=tail.next;
}
else head=tail=new intsllnode(el);
}
private int getint(String msg) {
System.out.print(msg + " ");
System.out.flush();
try {
input = buffer.readLine();
} catch(IOException io) {
}
return input;
}

public void run() {
while (true) {
char option = getString("\nEnter one of the following options:\n" +
"1. addtotail\n" +
"2. find\n" +
"3. delete\n" +"4.statues\n"+
"Your option:").charAt(0);
switch (option) {
case '1': addtotail(int el); break; // .class'expected 下面两个都是同样的错误 我是初学者 高手帮忙!!!
case '2': System.out.print(find(int el)); break;
case '3': delete(int el); break;
case '4': printall(); break;
case '5': return;
default: System.out.println("Wrong option, try again.");
}
}
}

public static void main(String args[]) {
(new intsllist()).run();
}
}

搜索更多相关主题的帖子: expected class 
2007-01-04 11:56
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
这是什么程序啊,哪有这样的
case '1': addtotail(int el); break; // .class'expected 下面两个都是同样的错误 我是初学者 高手帮忙!!!
case '2': System.out.print(find(int el)); break;
case '3': delete(int el); break;


你调用方法的时候,必须传入相应的参数,int el是什么东西,你必须传入特定值的参数

可惜不是你,陪我到最后
2007-01-04 13:28
海狂
Rank: 1
等 级:新手上路
威 望:1
帖 子:234
专家分:0
注 册:2006-12-26
收藏
得分:0 


import java.io.*;

class intsllnode{
public int info;
public intsllnode next;
public intsllnode (int i) {
this (i,null);
}
public intsllnode (int i,intsllnode n) {
info=i;next=n;
}
}
public class intsllist{
protected intsllnode head,tail;
private int input;
private BufferedReader buffer = new BufferedReader(
new InputStreamReader(System.in));
public intsllist() {
head=tail=null;
}

public boolean isempty() {
return head==null;
}

public void printall(){
for (intsllnode tmp=head;
tmp!=null;
tmp=tmp.next )
System.out.print(tmp.info+"");
}

public void delete (int el){
el=getint("I want delete this num");
if(head!=null)
if (el==head.info)
head=head.next;
else{
intsllnode pred=head,tmp=head.next;
for(;tmp!=null&&el!=tmp.info;
pred=pred.next,tmp=tmp=tmp.next)
if (tmp!=null)
pred.next=tmp.next;
}
}
public int find(int el){
el=getint("find this num");
intsllnode tmp=head;
for (;tmp!=null&&el!=tmp.info;
tmp=tmp.next)
if (tmp==null)
return null; //此方法不是定义为int了嘛 返回null?
else return tmp.info;
}
public void addtotail(int el){
el=getint("insert a num");
if (!isempty()){
tail.next=new intsllnode(el);
tail=tail.next;
}
else head=tail=new intsllnode(el);
}
private int getint(String msg) {
System.out.print(msg + " ");
System.out.flush();
try {
input = buffer.readLine(); // input 是int的 !
//buffer.readLine();是String!
} catch(IOException io) {
}
return input;
}

public void run() {
int el; //这里定义一下el 自己赋值
while (true) {
char option = getString("\nEnter one of the following options:\n" +"1. addtotail\n" +"2. find\n" +"3. delete\n" +"4.statues\n"+"Your option:").charAt(0);
//上面那句你想做什么??
switch (option) {
case '1': addtotail(el); break; // .class'expected 下面两个都是同样的错误 我是初学者 高手帮忙!!!
case '2': System.out.print(find(el)); break;
case '3': delete(el); break;
case '4': printall(); break;
case '5': return;
default: System.out.println("Wrong option, try again.");
}
}
}

public static void main(String args[]) {
(new intsllist()).run();
}
}


[此贴子已经被作者于2007-1-4 13:31:32编辑过]


2007-01-04 13:29
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
错误太多,建议重写

可惜不是你,陪我到最后
2007-01-04 14:31
sizki
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-9-14
收藏
得分:0 
太谢谢了,期末考试要用java 哎 有点无奈了都
晚上重写一遍,要是不行的话还得麻烦你们

char option = getString("\nEnter one of the following options:\n" +"1. addtotail\n" +"2. find\n" +"3. delete\n" +"4.statues\n"+"Your option:").charAt(0);
//上面那句你想做什么??

发现这句是完全错的。。。汗 本来的意思是打印出
Enter one of the following options
1. addtotail
2. find。。。。然后输入1,2,3选择相应的功能的,再看一便发现getString()这个方法我没写上去。。。

ps:发现这个论坛上版主很负责任,赞
2007-01-04 17:24
angeloc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:36
帖 子:1353
专家分:0
注 册:2006-11-21
收藏
得分:0 
以下是引用sizki在2007-1-4 17:24:03的发言:
太谢谢了,期末考试要用java 哎 有点无奈了都
晚上重写一遍,要是不行的话还得麻烦你们

char option = getString("\nEnter one of the following options:\n" +"1. addtotail\n" +"2. find\n" +"3. delete\n" +"4.statues\n"+"Your option:").charAt(0);
//上面那句你想做什么??

发现这句是完全错的。。。汗 本来的意思是打印出
Enter one of the following options
1. addtotail
2. find。。。。然后输入1,2,3选择相应的功能的,再看一便发现getString()这个方法我没写上去。。。

ps:发现这个论坛上版主很负责任,赞

努力吧!


老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-01-04 17:25
sizki
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-9-14
收藏
得分:0 

呵呵,搞出来了,谢谢三楼的提醒,我把int 都改成了 String 型就ok了!!谢谢了 贴出程序。。

不过发现一个比较弱的问题,说出来不要见笑。。。就是我先用for循环时没有打分号,编译却通过了

但是delete功能就不能实现了,总是随机的删除一个数,不知道是怎么回事,能再给个解释么 谢谢了

import java.io.*;

class intsllnode{
public String info;
public intsllnode next;
public intsllnode (String i) {
this (i,null);
}
public intsllnode (String i,intsllnode n) {
info=i;next=n;
}
}
public class intsllist{
protected intsllnode head,tail;
private String input;
private BufferedReader buffer = new BufferedReader(
new InputStreamReader(System.in));
public intsllist() {
head=tail=null;
}

public boolean isempty() {
return head==null;
}

public void printall(){
for (intsllnode tmp=head;
tmp!=null;
tmp=tmp.next )
System.out.print(tmp.info+" ");

}
public String find(){
String el=getstring("find this num");
intsllnode tmp=head;
for (;tmp!=null&&!el.equals(tmp.info);
tmp=tmp.next);
if (tmp==null)
return null;
else return tmp.info;
}

public void delete (){
String el=getstring("I want delete this num");
if(head!=null)
if (el.equals(head.info))
head=head.next;
else{
intsllnode pred=head,tmp=head.next;
for(;tmp!=null&&!el.equals(tmp.info);
pred=pred.next,tmp=tmp.next);
if (tmp!=null)
pred.next=tmp.next;
}
}

public void addtotail(){
String el=getstring("insert a num");
if (!isempty()){
tail.next=new intsllnode(el);
tail=tail.next;
}
else head=tail=new intsllnode(el);
}
private String getstring(String msg) {
System.out.print(msg + " ");
System.out.flush();
try {
input = buffer.readLine();
} catch(IOException io) {
}
return input;
}

public void run() {
while (true) {
char option = getstring("\nEnter one of the following options:\n" +
"1. addtotail\n" +
"2. find\n" +
"3. delete\n" +"4.statues\n"+
"Your option:").charAt(0);
switch (option) {
case '1': addtotail(); break;
case '2': System.out.print(find()); break;
case '3': delete(); break;
case '4': printall(); break;
case '5': return;
default: System.out.println("Wrong option, try again.");
}
}
}

public static void main(String args[]) {
(new intsllist()).run();
}
}

2007-01-04 19:30
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
你for后面加个分号干什么

可惜不是你,陪我到最后
2007-01-04 19:44
sizki
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-9-14
收藏
得分:0 
??我找了本书,一模一样的搬下来的。。。。
2007-01-04 20:36
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
for (;tmp!=null&&!el.equals(tmp.info);

不要说得这么绝对嘛

你肯定抄错了

可惜不是你,陪我到最后
2007-01-04 20:52
快速回复:求助.class'expected是什么错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013261 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved