求高人帮助java

来源:百度知道 编辑:UC知道 时间:2024/05/26 18:15:31
本人是菜鸟 这个java程序我用很久才完成,但是输入java后总是说有1 error,我死也找不到,求人帮助
import java.io.*;
class cc{
String getQuestion1(){

String txt1="Menu";
try{
DataInput d= new DataInputStream(new FileInputStream(txt1+".txt"));

while(txt1!=null){
System.out.println(txt1);
txt1=d.readLine();}

} catch (Exception e)
{String msg=e.toString();
System.out.println(msg);}

System.out.println();
System.out.println();

}
} // end of method getQuestion1

String getQuestion2(){
DataInput d= new DataInputStream(System.in);
String txt="";
int x=0;

try{
System.out.print("Choose order: ");

while((txt=d.readLine())!=null){
int a=Integer.parseInt(txt);
x=a;
if (a==1){
System.out.println("single size $1000");
System.out.println();
break;}

if (a==2){
S

问题很多,不考虑你要做什么,单说代码:
一:第21行多了一个 } ,去掉。
二:51行缺少catch,添加 }catch(Exception e){}
三:程序最后少个 } ,加上
四:getQuestion1()和getQuestion2()缺少返回值。

你所说的一个错误是因为21行多了个大括号,导致getQuestion2()及之后的代码不在类cc中,所以其他问题也都没在显示出来。

把你调好了,错在:
getQuestion2没有catch,
getQuestion1和getQuestion2都没有返回值.
照你的程序,运行前要先建个Menu.txt文件.

import java.io.*;

class cc {
String getQuestion1() {

String txt1 = "Menu";
try {
DataInput d = new DataInputStream(
new FileInputStream(txt1 + ".txt"));

while (txt1 != null) {
System.out.println(txt1);
txt1 = d.readLine();
}

} catch (Exception e) {
String msg = e.toString();
System.out.println(msg);
}

System.out.println();
System.out.println();
return "";
}

// end of method getQuestion1

String getQuestion2() {
DataInput d