我有两个班级文件&我无法在日食中发射。第一个:
import java.util.Scanner;
class bear{
public static void main(String[] args){
Scanner Bugs = new Scanner(System.in);
System.out.println("Please enter your name");
pee obj1 = new pee();
String Name = Bugs.nextLine();
obj1.PrintMessage(Name);
Bugs.close();
} }
第二个:
public class pee {
public void PrintMessage(String Name){
System.out.println("Hello, your name is:" + Name);
}
}
答案 0 :(得分:2)
主要课程应始终公开
public class bear{
public static void main(String[] args){
Scanner Bugs = new Scanner(System.in);
System.out.println("Please enter your name");
pee obj1 = new pee();
String Name = Bugs.nextLine();
obj1.PrintMessage(Name);
Bugs.close();
}
}
答案 1 :(得分:0)
您需要对类和变量使用Java命名约定,如下所示:
import java.util.Scanner;
public class Bear{
public static void main(String[] args){
Scanner bugs = new Scanner(System.in);
System.out.println("Please enter your name");
Pee obj1 = new Pee();
String name = bugs.nextLine();
obj1.PrintMessage(name);
bugs.close();
}
}
第二节课:
class Pee {
public void printMessage(String name){
System.out.println("Hello, your name is:" + name);
}
}
答案 2 :(得分:0)
如果您的java文件是bear.java,则需要在类bear上声明public。 以下是示例代码: bear.java
public class bear {
public static void main(String[] args) {
Scanner Bugs = new Scanner(System.in);
System.out.println("Please enter your name");
pee obj1 = new pee();
String Name = Bugs.nextLine();
obj1.PrintMessage(Name);
Bugs.close();
}
}
class pee {
public void PrintMessage(String Name) {
System.out.println("Hello, your name is:" + Name);
}
}