所以我需要用java编写一个程序,用2个用户输入摄氏温度并将其转换为华氏度和开氏度。我写了代码,它在eclipse中工作,但我的老师严格地说它必须在cmd中工作。它编译得很好,但是当我去运行它时,它指出could not find or load main class temperatureTester
(我的主类的名字)。这是我的第一篇文章,所以如果你需要更多的信息,请问,我正在寻找任何想法,为什么发生这种情况。下面是我的问题代码。如何在cmd上运行java中的2个连接类?
import java.util.Scanner;
public class temperatureTester{
public static void main (String[]args){
//create 2 objects connecting to temperatureC
temperatureC firstValue = new temperatureC();
temperatureC secondValue = new temperatureC();
// initialize scanner
Scanner stdin = new Scanner (System.in);
//initialize variables
double firstC = 0;
double secondC = 0;
//prompt user for both values
System.out.print("Please enter initial temperatures: ");
firstC = stdin.nextDouble();
secondC = stdin.nextDouble();
//call object set methods and pass entered values as arguments
firstValue.setC(firstC);
secondValue.setC(secondC);
//display the values for the values for different temp. units
System.out.println("1) The current temperature in Celcius is: " + firstValue.getC());
System.out.println("1) The current temperature in fahreinheit is: " + firstValue.getF());
System.out.println("1) The current temperature in kelvin is: " + firstValue.getK());
System.out.println("---------------------------------------------------------------");
System.out.println("2) The current temperature in Celcius is: " + secondValue.getC());
System.out.println("2) The current temperature in fahreinheit is: " + secondValue.getF());
System.out.println("2) The current temperature in kelvin is: " + secondValue.getK());
这是第二类
public class temperatureC{
private double C;
/**
The setC method stores the value in the C field
@ param initialC the value stored in C
*/
public void setC(double initialC){
C = initialC;
}
/**
The getC returns the C value and also sets a lower limit,
if a number below is entered it sets it ti the limit.
@Return the value of the C
*/
public double getC(){
if(C < -273.15){
C = -273.15;
}
return C;
}
/**
the getF method calculates and returns a value for C in fahrenheit
@return the computed for C in fahrenheit
*/
public double getF(){
return C * 1.8 + 32;
}
/**
The getK method computes and returns a value for temperature C in kelvin
@return the computed Kelvin value
*/
public double getK(){
return C + 273.15;
}
}
你怎么运行它?你能发布你的命令吗? – root545
请注意,Java类应以'CapitalLetters'开头 –