运行代码的问题
获取持续的非法转义字符
声明变量和似乎声明正确的字符串。
import java.swing.*;
import java.text.DecimalFormat;
public class TWP1Project {
private static Object dataIn;
public static void main(String[] args) {
// declare class variables
int hours;
double fee, rate, tuition;
// call methods
displayWelcome();
hours = getHours();
rate = getRate();
tuition = calcTuition(hours);
fee = myArray(1);
diplayTotal(tuition+fee);
}
public static void displayWelcome()
{
System.out.println("\Welcome to the Tuition and Fees Calculator");
}
}
public static int getHours()
{
//declare variables
String strHours;
int hours = 0;
//prompts user for input
System.out.println("Enter the number of hours accrued in a class.");
hours = dataIn.readLine();
try
{
hours = Integer.parseInt(strHours);
}
catch{NumberFormatException e};
JOptionPane.showMessageDialog{null,"Your entry was not in the proper format.",
"Error"JOptionPane.INFORMATION_MESSAGE};
{
System.out.println("Please input whole numbers only");
}
return hours;
}
//the getRate() method ask user to input the rate per credit hours.
public static double getRate()
{
int hours =12;
if (hours>12)
System.out.println("calculate the rate per credit hours");
else
if (hours<12)
System.out.println("credit hours is inaccurate");
else
System.out.println("zero");
}
}
return rate;
//the calcTuition() allowed to calculate tuition.
public static double calcTuition()
{`enter code here`
int hours
double rate =0.0;
double rate * hours
}
return tuition;
//
public static myArray(int tuition)
{
int tuition
double fee
}
return fee
如果可以或提供一些提示,需要帮助纠正。 在java中正确运行它的问题。
答案 0 :(得分:2)
从\
System.out.println("\Welcome to the Tuition and Fees Calculator");
答案 1 :(得分:1)
或者如果你的消息中需要“\”,请加上双反斜杠。
试试这个:
public static void displayWelcome()
{
System.out.println("\\Welcome to the Tuition and Fees Calculator");
}
更多信息:https://docs.oracle.com/javase/tutorial/java/data/characters.html
答案 2 :(得分:1)
你有多个错误,我已经解决了其中的一些错误,并给你一些指示...请在编写代码时使用Netbeans或Eclipse等IDE ...我已经将其他一些留给了你,并解释了你应该对他们做些什么
import java.io.Console;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class TWP1Project {
private static Console dataIn; // if you want to read from keyboard or
// something, this should be of type
// Scanner, not Object - to use it you need
// to also add import java.util.Scanner;
public static void main(String[] args) {
// declare class variables
int hours;
double fee, rate, tuition;
// call methods
displayWelcome();
hours = getHours();
rate = getRate();
tuition = calcTuition(hours);
fee = myArray(1); // you have
diplayTotal(tuition + fee);
}
public static void displayWelcome() {
System.out.println("Welcome to the Tuition and Fees Calculator"); // no
// backslash
} // erased one brace this
public static int getHours() {
// declare variables
String strHours; // you didn't initialize strHours
int hours = 0;
// prompts user for input
System.out.println("Enter the number of hours accrued in a class.");
dataIn = System.console(); // need to initialize in order to read lines
// from it
hours = Integer.parseInt(dataIn.readLine()); // this doesn't prompt for
// input, you need a
// scanner object
try {
hours = Integer.parseInt(strHours); // didn't initialize strHours
} catch (NumberFormatException e) {
} // pay attention here
JOptionPane.showMessageDialog(null,
"Your entry was not in the proper format.", "Error",
JOptionPane.INFORMATION_MESSAGE); // you need ( , not {
{
System.out.println("Please input whole numbers only");
}
return hours;
}
// the getRate() method ask user to input the rate per credit hours.
public static double getRate() {
int hours = 12;
if (hours > 12)
System.out.println("calculate the rate per credit hours");
else if (hours < 12)
System.out.println("credit hours is inaccurate");
else
System.out.println("zero");
return rate; // you need to initialize the rate somewhere...i'll let
// this for you
}
// the calcTuition() allowed to calculate tuition.
public static double calcTuition() {
int hours;
double rate = 0.0;
double tuition = rate * hours; // i don't actually know what you meant
// here, but you should declare the
// tuition and then initialize it
return tuition;
}
//
public static myArray(int tuition) // you forgot the return type
{
// don't know what you meant here, but again, initialize
double fee;
return fee;
}
}