java代码在pta上运行的注意事项
main方法所在的类,类名用Main。
在pta上运行如下java代码:
public class Test
{
public static void main(String[] args) {
System.out.println("Hell World!");
}
}
pta将报如下错误:
public类的更改
如果在一个题中,除了要写主类,也要写其他的一些类来完成特定的功能,其他的类的前面的public修饰符要去掉
public class Print
{
void f()
{
System.out.println("Hell World!");
}
}
public class Main
{
public static void main(String[] args) {
Print print = new Print();
print.f();
}
}
pta将报如下错误:
去掉class Print前面的public即可运行。