相对较新的java编程,我的代码输出错误,因为它与swing方面有关
import java.io.*;
import Java.text.DecimalFormat;
public class CurrencyConverter
{
public static void main(string[]args)throws IOException
{
String USDollar;
double USD, Euro, Pounds, Rouble;
BufferedReader dataIn=new BufferedReader (newInputStreamReader(System.in));
System.out.println();
System.out.println("\t\t CURRENCY CONVERTER");
System.out.println("\t\t Please enter the Dollar amount in US DOLLAR");
USDollar=dataIn.readLine();
USD=Double.parseDouble(USDollar);
Rouble=(USD*34.89);
Pounds=(USD*0.61);
Euro=(USD*0.73);
System.out.println();
System.out.println("\t\tYour given amount $"+USD);
System.out.println("\t\tPounds $"+ Pounds);
System.out.println("\t\tRussian Rouble $"+ Rouble);
System.out.println("\t\tEuro $"+Euro);
}
}
import javax.swing.JOptionPane;
public class CSwing
{
public static void main(String[]args)
{
String USDollar;
double USD,Pounds,Rouble,Euros;
System.out.println("t\tCURRENCY CONVERTER");
USD = JOptionPane.showInputDialog(null,"Please enter the Dollar amount in USD");
dUSD=Double.parseDouble(USD);
Rouble=(USD*34.89);
Pounds=(USD*0.61);
Euro=(USD*0.73);
JOptionPane.showMessageDialog(null, "Your Given Amount: $" +(dUSD)
+"\n\nYour Rouble Conversion is:$"+(Rouble)
+"\n\nYour Pound Conversion is:$"+(Pound)
+"\n\nYour Euro Conversion is:$"+(Euro));
System.exit(0);
}
}
工具输出错误:class, interface, enum expected: import javax.swing.JOptionpane
:
我用谷歌搜索了这个,试图自己解决它,但我被卡住了。我已经解决了目前存在的所有其他错误,这是唯一剩下的错误,但为什么我遇到这个错误。您对此的帮助将非常感激。
答案 0 :(得分:2)
在这一行中:dUSD=Double.parseDouble(USD);
您试图从Double
解析USD
已经是双倍的Double.parseDouble(String S)
。
String
需要将Double
参数传递给它。不是import javax.swing.JOptionPane;
public class CSwing {
public static void main(String[] args) {
String usd;
double dUSD, pounds, rouble, euros;
System.out.println("t\tCURRENCY CONVERTER");
usd = JOptionPane.showInputDialog(null,
"Please enter the Dollar amount in USD");
dUSD = Double.parseDouble(usd);
rouble = (dUSD * 34.89);
pounds = (dUSD * 0.61);
euros = (dUSD * 0.73);
JOptionPane.showMessageDialog(null, "Your Given Amount: $" + (dUSD)
+ "\n\nYour Rouble Conversion is:$ " + (rouble)
+ "\n\nYour Pound Conversion is:$ " + (pounds)
+ "\n\nYour Euro Conversion is:$ " + (euros));
System.exit(0);
}
}
。
快速修复:
CurrencyConverter
至于你的import java.io.*;
public class CurrencyConverter {
public static void main(String[] args) throws IOException {
String usDollar;
double usd, euro, pounds, rouble;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
System.out.println();
System.out.println("\t\t CURRENCY CONVERTER");
System.out.println("\t\t Please enter the Dollar amount in US DOLLAR");
usDollar = dataIn.readLine();
usd = Double.parseDouble(usDollar);
rouble = (usd * 34.89);
pounds = (usd * 0.61);
euro = (usd * 0.73);
System.out.println();
System.out.println("\t\tYour given amount $" + usd);
System.out.println("\t\tPounds $" + pounds);
System.out.println("\t\tRussian Rouble $" + rouble);
System.out.println("\t\tEuro $" + euro);
}
}
,一切似乎都只是一些小的印刷错误。
修正:
{{1}}
答案 1 :(得分:1)
您必须在所有类声明之前导入所有内容。因此,使用所有其他声明将import javax.swing.JOptionPane;
移至顶部。或者像@assylias指出的那样只是将两个类分成不同的文件。哦,并且包import Java.text.DecimalFormat;
不存在,请将'j'改为'Java'小写。