当前位置: 技术问答>java相关
下面代码编译不能通过,提示 'class' or 'interface' expected;多谢
来源: 互联网 发布时间:2015-09-14
本文导语: public class ManKind { int sex; int salary; void manOrWoman(int sexValue) { switch (sexValue) { case 0: System.out.println("a man"); break; case 1: System.out.println("a woman"); break; default: System.out.println("not a man or a woman...
public class ManKind
{
int sex;
int salary;
void manOrWoman(int sexValue)
{
switch (sexValue)
{
case 0:
System.out.println("a man");
break;
case 1:
System.out.println("a woman");
break;
default:
System.out.println("not a man or a woman");
}
}
void employed (int salaryValue)
{
if (salaryValue==0)
System.out.println("no job");
else
System.out.println("have job");
}
}
public static void main (String args[])
{
ManKind somePerson=new ManKind();
somePerson.sex=1;
somePerson.manOrWoman(someperson.sex);
somePerson.salary=5;
somePerson.employed(somePerson.salary);
try
{
System.in.read();
}
catch(Exception e)
{}
}
{
int sex;
int salary;
void manOrWoman(int sexValue)
{
switch (sexValue)
{
case 0:
System.out.println("a man");
break;
case 1:
System.out.println("a woman");
break;
default:
System.out.println("not a man or a woman");
}
}
void employed (int salaryValue)
{
if (salaryValue==0)
System.out.println("no job");
else
System.out.println("have job");
}
}
public static void main (String args[])
{
ManKind somePerson=new ManKind();
somePerson.sex=1;
somePerson.manOrWoman(someperson.sex);
somePerson.salary=5;
somePerson.employed(somePerson.salary);
try
{
System.in.read();
}
catch(Exception e)
{}
}
|
}的位置放错了。
public class ManKind
{
int sex;
int salary;
void manOrWoman(int sexValue)
{
switch (sexValue)
{
case 0:
System.out.println("a man");
break;
case 1:
System.out.println("a woman");
break;
default:
System.out.println("not a man or a woman");
}
}
void employed (int salaryValue)
{
if (salaryValue==0)
System.out.println("no job");
else
System.out.println("have job");
}
//}
public static void main (String args[])
{
ManKind somePerson=new ManKind();
somePerson.sex=1;
somePerson.manOrWoman(someperson.sex);
somePerson.salary=5;
somePerson.employed(somePerson.salary);
try
{
System.in.read();
}
catch(Exception e)
{}
}
} // ···
public class ManKind
{
int sex;
int salary;
void manOrWoman(int sexValue)
{
switch (sexValue)
{
case 0:
System.out.println("a man");
break;
case 1:
System.out.println("a woman");
break;
default:
System.out.println("not a man or a woman");
}
}
void employed (int salaryValue)
{
if (salaryValue==0)
System.out.println("no job");
else
System.out.println("have job");
}
//}
public static void main (String args[])
{
ManKind somePerson=new ManKind();
somePerson.sex=1;
somePerson.manOrWoman(someperson.sex);
somePerson.salary=5;
somePerson.employed(somePerson.salary);
try
{
System.in.read();
}
catch(Exception e)
{}
}
} // ···
|
除了上面的问题解决外,
你还要注意,
你的 CLASS NAME 和你的文件名是不是大小写一致的。
你还要注意,
你的 CLASS NAME 和你的文件名是不是大小写一致的。
|
把main前面的} 放到最后面,main要包含在class里面