Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我把双打放在最上面时,程序不会';我跑不好_Java_Variables - Fatal编程技术网

Java 当我把双打放在最上面时,程序不会';我跑不好

Java 当我把双打放在最上面时,程序不会';我跑不好,java,variables,Java,Variables,赋值:变量 此程序提示用户输入介于-58°F和-58°F之间的温度 41°F且风速大于或等于2,则显示 显示风寒温度 // Imports util.Scanner import java.util.Scanner; public class Windchill { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Tempurature

赋值:变量 此程序提示用户输入介于-58°F和-58°F之间的温度 41°F且风速大于或等于2,则显示 显示风寒温度

// Imports util.Scanner
import java.util.Scanner; 

public class Windchill {

    public static void main(String[] args) { 
    Scanner input = new Scanner(System.in);

    // Tempurature
    double temperature = input.nextDouble();
    // Windspeed
    double speed = input.nextDouble();
    // Compute the wind chill tempurature
    double windChill = 35.74 + 0.6215 * temperature -         
                   35.75 * Math.pow(speed, 
                           0.16) + 0.4275 * temperature * 
                           Math.pow(speed, 0.16);

    // Prompt the user to enter a temperature between -58F and 41F.
    System.out.print("Enter the temperature in Fahrenheit " +
    "between -58\u00b0F and 41\u00b0F: ");

    // Prompt the user to enter the wind speed greter than or equal to 2.
    System.out.print("Enter the wind speed (>= 2) in miles per hour: ");

    // Display result
    System.out.println("The wind chill tempurature is " + windChill);

        }
}

只需像下面那样重新排列代码

// Imports util.Scanner
import java.util.Scanner; 

public class Windchill {

    public static void main(String[] args) { 
    Scanner input = new Scanner(System.in);

            // Prompt the user to enter a temperature between -58F and 41F.
    System.out.print("Enter the temperature in Fahrenheit " +
    "between -58\u00b0F and 41\u00b0F: ");
    // Tempurature
    double temperature = input.nextDouble();
        // Prompt the user to enter the wind speed greter than or equal to 2.
    System.out.print("Enter the wind speed (>= 2) in miles per hour: ");
    // Windspeed
    double speed = input.nextDouble();
    // Compute the wind chill tempurature
    double windChill = 35.74 + 0.6215 * temperature -         
                   35.75 * Math.pow(speed, 
                           0.16) + 0.4275 * temperature * 
                           Math.pow(speed, 0.16);

    // Display result
    System.out.println("The wind chill tempurature is " + windChill);

        }
}

但这似乎是学校的一项作业。然而,看起来你已经完成了大部分工作。祝贺现在,我觉得这里的问题可以通过解释为什么你的程序在“双打领先”的情况下不起作用来解决。我希望我的回答能帮助您更好地理解java解释代码的方式

无需进一步ado,所有类型的编程语言都有变量。Java也不例外。例如

    double number = 0.0; // Java variable declaration
    number = 0.0 # Python variable declaration
    var number = 0.0 // JavaScript variable declaration
您的代码将自上而下执行。这方面的说明如下所示

int money = 0;
System.out.println(money);
money = 10;
System.out.println(money);
money = 9000;
System.out.println("I have over " + money);
这将输出

0
10
I have over 9000
但是,如果您像下面这样编写此代码

System.out.println(money);
int money = 0;
你会得到一个错误!这是因为行刑还没有看到金钱是一种东西!这就像不用牙刷刷牙一样。你不能,因为你没有刷子

因此,这同样适用于您的程序

public static void main(String[] args) { 
    double temperature = input.nextDouble();
    Scanner input = new Scanner(System.in);

            // Prompt the user to enter a temperature between -58F and 41F.
    System.out.print("Enter the temperature in Fahrenheit " +
    "between -58\u00b0F and 41\u00b0F: ");
    // Tempurature

        // Prompt the user to enter the wind speed greter than or equal to 2.
    System.out.print("Enter the wind speed (>= 2) in miles per hour: ");
    // Windspeed
    double speed = input.nextDouble();
    // Compute the wind chill tempurature
    double windChill = 35.74 + 0.6215 * temperature -         
                   35.75 * Math.pow(speed, 
                           0.16) + 0.4275 * temperature * 
                           Math.pow(speed, 0.16);

        // Display result
    System.out.println("The wind chill tempurature is " + windChill);

}

注意扫描线上方的温度。输入是您创建的一个对象,用于在该双精度中读取。如果在创建输入对象之前尝试使用此选项,程序将不知道该输入对象是什么

谢谢大家。我明白了

/*赋值:变量 此程序提示用户输入介于-58°F和41°F之间的温度 风速大于或等于2时,将显示 风寒的温度。 */

//导入util.Scanner 导入java.util.Scanner

公共级风寒机{

public static void main(String[] args) {
    // Declare variables
    double temperature;
    double windspeed;
    double wind_chill;

    // Create a Scanner object to read input
    Scanner input = new Scanner(System.in);

    // Prompt the user to enter a temperature between -58F and 41F.
    System.out.print("Enter the temperature in Fahrenheit " +
                     "between -58\u00b0F and 41\u00b0F: ");
    temperature = input.nextDouble();       

    // Prompt the user to enter the wind speed greter than or equal to 2.
    System.out.print("Enter the wind speed (>= 2) in miles per hour: ");
    windspeed = input.nextDouble();

    // Display result
    wind_chill = 35.74 + 0.6215 * temperature -
               35.75 * Math.pow(windspeed, 0.16) +
               0.4275 * temperature * Math.pow(windspeed, 0.16);

    System.out.println("The wind chill temprature is " + wind_chill);

}

}

你说的“运行不正常”是什么意思?另外,为什么要将提示放在收集用户输入的位置之后?在提示用户键入内容之前尝试获取输入可能不是您想要的。如果它不能正常运行,它将如何运行?你想问个问题吗?另外,如果你没有“把双打放在最上面”时它运行正常,就不要把双打放在最上面。