我遇到了问题,因为我不是很擅长Java。你可以帮帮我吗。
请注意:它不是重复的,因为指定了类路径并且我已经完成了#34;重复的问题"。
你能指点我正确的方向吗?
我的代码编译得很好,所有已编译的文件以及原始文件都存储在桌面上。
错误
Desktop beeeeaasssst$ java com.StudentDemo
Error: Could not find or load main class com.StudentDemo
Caused by: java.lang.ClassNotFoundException: com.StudentDemo
CODE
package com;
public class StudentDemo {
public static void main(String[] args) {
Student one = new Student(1,"Ravi",45);
Student two = new Student(2,"Amit",65);
Student three = new Student(3,"pooka",55);
System.out.println("Student with highest marks is " + compareStudents(one,two,three));
}
public static String compareStudents (Student one, Student two, Student three) {
Student st = one;
if (two.getMarks() > st.getMarks())
st=two;
if (three.getMarks() > st.getMarks())
st=three;
return st.getName();
}
}
class Student {
private int rollNo;
private String name;
private double marks;
public Student (int rollNo, String name, double marks) {
this.rollNo = rollNo;
this.name = name;
this.marks = marks;
}
public double getMarks(){
return marks;
}
public void setMarks(double marks){
this.marks = marks;
}
public int getRollNo() {
return rollNo;
}
public String getName(){
return name;
}
}
代码编译并生成2个不同的类文件,但我无法运行该程序。我从我的终端尝试了两种方式:
java com.StudentDemo . (Since package used is com).
你能指点我正确的方向吗?
答案 0 :(得分:1)
com/StudentDemo.java
。javac com/StudentDemo.java
汇总。java com.StudentDemo
执行。大部分内容已在duplicate的接受答案中明确说明。