未找到主要 class,
No main class found,
这是一个新手问题,为什么我会收到一条消息说我没有任何主要 class。我是一个完全的初学者,我已经尝试阅读有关此问题的所有其他答案。我在 netbeans 工作。
/**
* @author Anders
*/
public class Main {
public enum Valuta { // here i assign the values i allow from the argument
EUR,
USD,
RUB;
// here i assign the conversionrates
static final float C_EUR_TO_DKK_RATE = (float) 7.44;
static final float C_USD_TO_DKK_RATE = (float) 5.11;
static final float C_RUB_TO_DKK_RATE = (float) 0.156;
static float result = 0;
static int value = 0;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length == 2) {
value = Integer.parseInt(args[0]);
String valutaIn = args[1]; //equalsIgnoreCase(null) boolean expression. How does this works??
Valuta enumConvert = Valuta.valueOf(valutaIn);
switch (enumConvert) {
case EUR:
result = value * C_EUR_TO_DKK_RATE;
break;
case USD:
result = value * C_USD_TO_DKK_RATE;
break;
case RUB:
result = value * C_RUB_TO_DKK_RATE;
break;
}
System.out.println((float) value + "" + enumConvert + " converts to " + (result * 100.) / 100.0 + "Dk");
}
else {
System.exit(1);
}
}
}
}
main 方法不在 Class Main 中,它在枚举 Valuta 中。您可能打算执行以下操作(注意枚举后的右大括号):
/**
* @author Anders
*/
public class Main {
public enum Valuta { // here i assign the values i allow from the argument
EUR,
USD,
RUB;
}
// here i assign the conversionrates
static final float C_EUR_TO_DKK_RATE = (float) 7.44;
static final float C_USD_TO_DKK_RATE = (float) 5.11;
static final float C_RUB_TO_DKK_RATE = (float) 0.156;
static float result = 0;
static int value = 0;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length == 2) {
value = Integer.parseInt(args[0]);
String valutaIn = args[1]; //equalsIgnoreCase(null) boolean expression. How does this works??
Valuta enumConvert = Valuta.valueOf(valutaIn);
switch (enumConvert) {
case EUR:
result = value * C_EUR_TO_DKK_RATE;
break;
case USD:
result = value * C_USD_TO_DKK_RATE;
break;
case RUB:
result = value * C_RUB_TO_DKK_RATE;
break;
}
System.out.println((float) value + "" + enumConvert + " converts to " + (result * 100.) / 100.0 + "Dk");
}
else {
System.exit(1);
}
}
}
这是一个新手问题,为什么我会收到一条消息说我没有任何主要 class。我是一个完全的初学者,我已经尝试阅读有关此问题的所有其他答案。我在 netbeans 工作。
/**
* @author Anders
*/
public class Main {
public enum Valuta { // here i assign the values i allow from the argument
EUR,
USD,
RUB;
// here i assign the conversionrates
static final float C_EUR_TO_DKK_RATE = (float) 7.44;
static final float C_USD_TO_DKK_RATE = (float) 5.11;
static final float C_RUB_TO_DKK_RATE = (float) 0.156;
static float result = 0;
static int value = 0;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length == 2) {
value = Integer.parseInt(args[0]);
String valutaIn = args[1]; //equalsIgnoreCase(null) boolean expression. How does this works??
Valuta enumConvert = Valuta.valueOf(valutaIn);
switch (enumConvert) {
case EUR:
result = value * C_EUR_TO_DKK_RATE;
break;
case USD:
result = value * C_USD_TO_DKK_RATE;
break;
case RUB:
result = value * C_RUB_TO_DKK_RATE;
break;
}
System.out.println((float) value + "" + enumConvert + " converts to " + (result * 100.) / 100.0 + "Dk");
}
else {
System.exit(1);
}
}
}
}
main 方法不在 Class Main 中,它在枚举 Valuta 中。您可能打算执行以下操作(注意枚举后的右大括号):
/**
* @author Anders
*/
public class Main {
public enum Valuta { // here i assign the values i allow from the argument
EUR,
USD,
RUB;
}
// here i assign the conversionrates
static final float C_EUR_TO_DKK_RATE = (float) 7.44;
static final float C_USD_TO_DKK_RATE = (float) 5.11;
static final float C_RUB_TO_DKK_RATE = (float) 0.156;
static float result = 0;
static int value = 0;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length == 2) {
value = Integer.parseInt(args[0]);
String valutaIn = args[1]; //equalsIgnoreCase(null) boolean expression. How does this works??
Valuta enumConvert = Valuta.valueOf(valutaIn);
switch (enumConvert) {
case EUR:
result = value * C_EUR_TO_DKK_RATE;
break;
case USD:
result = value * C_USD_TO_DKK_RATE;
break;
case RUB:
result = value * C_RUB_TO_DKK_RATE;
break;
}
System.out.println((float) value + "" + enumConvert + " converts to " + (result * 100.) / 100.0 + "Dk");
}
else {
System.exit(1);
}
}
}