Java 嗨,我在阻止代码运行时出错了?
我一直在youtube上观看这些视频,使用底部git hub链接提供的源代码示例,一切都很好,但每次运行代码时,我都会出现这些错误 错误:无法找到或加载主类mathexample.mathexample C:\Users\JAC\AppData\Local\NetBeans\Cache\8.2\executor snippets\run.xml:53:Java返回:1 生成失败(总时间:0秒) 代码:Java 嗨,我在阻止代码运行时出错了?,java,Java,我一直在youtube上观看这些视频,使用底部git hub链接提供的源代码示例,一切都很好,但每次运行代码时,我都会出现这些错误 错误:无法找到或加载主类mathexample.mathexample C:\Users\JAC\AppData\Local\NetBeans\Cache\8.2\executor snippets\run.xml:53:Java返回:1 生成失败(总时间:0秒) 代码: 看起来无论您使用哪种IDE,您都没有将其指向主类。尝试查看您的项目设置,看看它试图执行什么 尝
看起来无论您使用哪种IDE,您都没有将其指向主类。尝试查看您的项目设置,看看它试图执行什么 尝试清理和重建项目是的,当我想向代码中添加内容时,尝试了一段时间,但现在不起作用。如果您使用IDE,请检查您尝试运行的项目的“运行配置”。我看到这是来自Netbeans。。。我正在使用Netbeans IDE,我对Netbeans不太熟悉,但请尝试一下这个链接。第14点以后可能会有用。谢谢,我会查一查,看起来会有帮助
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("/////////////////////////////////////////////////");
}
}