java expected_求助.class'expected是什么错误

呵呵,搞出来了,谢谢三楼的提醒,我把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();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值