学生用Java编写的结果程序
import java.io.DataInputstream;
class Student
{
int roll;
void getdata(int r)
{
roll=r;
}
void putroll()
{
System.out.println("The roll number is: "+roll);
}
}
class Test extends Student
{
int sub1,sub2;
void getmarks(int a, int b)
{
sub1=a;
sub2=b;
}
void putmarks()
{
System.out.println("Marks 1= "+ sub1 + "\n Marks 2= "+sub2);
}
interface Sport
{
float spt=6.0f;
void putspt(float num);
}
class Result extends Test implements Sport
{
float total;
float n;
public void putspt(float num)
{
x=num;
if(x>6 && x<=10)
System.out.println("Sport= "+x);
else
System.out.println("Sport= "+spt);
}
void display()
{
if(x>6 && x<=10)
total=sub1+sub2+x;
else
total=sub1+sub2+spt;
putroll();
putmarks();
if(x>6 && x<=10)
putspt(x);
else
putspt(spt);
System.out.println("Total marks= "+total);
}
}
class Student_Test
{
public static void main(String a[]) throws Exception
{
DataInputStream ds = new DataInputStream(System.in);
int a,b,c;
float d;
try
{
int t;
System.out.println("\nEnter total no. of Students:");
t=Integer.parseInt(ds.readLine());
for(int i=1;i<=t;i++)
{
System.out.println("Enter Roll no.:");
a=Integer.parseInt(ds.readLine());
System.out.println("Enter the marks of two subjects:");
b=Integer.parseInt(ds.readLine());
c=Integer.parseInt(ds.readLine());
System.out.println("Enter Sports marks:");
d=Integer.parseInt(ds.readLine());
Result r=new Result();
r.getroll(a);
r.getmarks(b,c);
r.putspt(d);
r.display();
}
}
catch(Exception e)
{
System.out.println("ERROR");
}
}
}
我在编译时遇到以下错误:
学生。java:97:解析时到达文件末尾 }-&燃气轮机
第97行是程序的最后一行
有人能帮我解决这个错误吗强>
# 1 楼答案
您缺少一个}来关闭您的测试类(大约完成了一半)
# 2 楼答案
Test
类没有右大括号# 3 楼答案
检查闭合支架
# 4 楼答案
# 5 楼答案
类测试缺少一个:
# 6 楼答案
您错过了类
Test
上interface Sport
之前的右大括号顺便说一句,如果正确格式化(特别是缩进)源代码,将来就不会有这样的问题