我一直在youtube上使用从底部的git hub链接提供的源代码示例观看这些视频,一切都很好,但每当我运行代码时我就开始收到这些错误
错误:无法找到或加载主类mathexample.MathExample C:\ Users \ JAC \ AppData \ Local \ NetBeans \ Cache \ 8.2 \ executor-snippets \ run.xml:53:Java返回:1 BUILD FAILED(总时间:0秒)
代码:
package mathexample;
import java.util.Random;
import java.util.Scanner;
public class MathExample {
public static void main(String[] args) {
System.out.println("//Math Example //////////////////////////////////");
// Circle Math
Scanner input = new Scanner(System.in);
System.out.print("Enter Circle Radius : ");
double radius = input.nextDouble();
double circ = 2*Math.PI*radius;// using math library
double area = Math.PI*radius*radius;
System.out.printf("Circumfrence : %f; Area : %f\n",circ, area);
System.out.println("///////////////////////////////////////////////\n");
System.out.println("//RandomExample /////////////////////////////////");
// Demonstrates use of an existing class
//random class
Random generator = new Random(); // 0 is the "seed" the same seed will
// generate the same random sequence
// Random() will use a random "seed"
int i = generator.nextInt(10); // pick a random number between 0 and 9
System.out.println(i);
i = generator.nextInt(10);// java doc explains classes right click to access it
System.out.println(i);
i = generator.nextInt(10);
System.out.println(i);
System.out.println("///////////////////////////////////////////////\n");
System.out.println("//StringBuilderExample //////////////////////////");
// demonstrates StringBuilder class
StringBuilder sb = new StringBuilder();//uses javadoc the learn
sb.append("This is a test!");
String forward = sb.toString();//you only need (new) when creating a new object
String reverse = sb.reverse().toString();// this uses the existing object
// on line 7 StringBuilder
System.out.println(forward);
System.out.println(reverse);
System.out.println("/////////////////////////////////////////////////");
}
}
答案 0 :(得分:1)
它看起来像你正在使用的任何一个IDE,你没有指向你的主类。尝试查看项目设置,看看它正在尝试执行什么。