首页 \ 问答 \ 运营顺序(Order of Operations)

运营顺序(Order of Operations)

我需要帮助解决输出代码问题。 很抱歉我需要帮助修复hI的输出。 可以找到两个输入文件(即将发布)

请询问您是否需要输出的内容或解决hI的公式(我只能发布两个链接。)。

import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class HeatIndex
{
    public static void main(String[] args) throws IOException
    {


    String location = "Key West, Florida";
    File fileNameTemp = new File("KeyWestTemp.txt");
    File fileNameHumid = new File("KeyWestHumid.txt");

    Scanner inFileTemp = new Scanner(fileNameTemp);
    Scanner inFileHumid = new Scanner(fileNameHumid);

    String [] month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novermber", "December"};
    int length = month.length;
    double [] temperature = new double[length];
    int [] humidity = new int[length];
    double [] hI = new double[length];


    //INPUT - read in data for temp and humidity from files

    int n = 0; //index value for arrays
    while( inFileTemp.hasNextDouble() )
    {
        temperature[n] = inFileTemp.nextDouble();
        //System.out.println (temperature[n]); //debug statement - uncomment to see values assignned to temperature
        n++;
    }
    inFileTemp.close();


    n = 0; //reset index to 0
    while (inFileHumid.hasNextDouble())
    {
            humidity[n] = inFileHumid.nextInt();
            //System.out.println (humidity[n]);  //debug statement - uncomment to see values assignned to humidity
            n++;
    }
    inFileHumid.close();

    //PROCESSING - calculate Heat Index if needed- see lecture notes for details, formula is incomplete

    double t = 0.0;
    int h = 0;

    for(n = 0; n < hI.length; n++)
    {
        if( temperature[n] >= 80.0  ) //determine if HI should be calculated, complete the condition based on Lecture notes
        {
            t = temperature[n];
            h = humidity[n];

            hI[n] = -42.379 + 2.04901523*t+ 10.1433312*h- 0.22475541*t*h- 0.000683783*(t*t)- 0.005481717* (h*h)+ 0.000122874*(h*h)*t+ 0.000085282*t*(h*h)- 0.000000199*(t*t)*(h*h);
}

I need help with solving my problem of output code. Sorry for the big chunk of code I need help fixing the output for hI. The two input files can be found (soon to be posted)

Please ask if you need what the output looks like or the formula for solving hI ( I can only post two links.).

import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class HeatIndex
{
    public static void main(String[] args) throws IOException
    {


    String location = "Key West, Florida";
    File fileNameTemp = new File("KeyWestTemp.txt");
    File fileNameHumid = new File("KeyWestHumid.txt");

    Scanner inFileTemp = new Scanner(fileNameTemp);
    Scanner inFileHumid = new Scanner(fileNameHumid);

    String [] month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novermber", "December"};
    int length = month.length;
    double [] temperature = new double[length];
    int [] humidity = new int[length];
    double [] hI = new double[length];


    //INPUT - read in data for temp and humidity from files

    int n = 0; //index value for arrays
    while( inFileTemp.hasNextDouble() )
    {
        temperature[n] = inFileTemp.nextDouble();
        //System.out.println (temperature[n]); //debug statement - uncomment to see values assignned to temperature
        n++;
    }
    inFileTemp.close();


    n = 0; //reset index to 0
    while (inFileHumid.hasNextDouble())
    {
            humidity[n] = inFileHumid.nextInt();
            //System.out.println (humidity[n]);  //debug statement - uncomment to see values assignned to humidity
            n++;
    }
    inFileHumid.close();

    //PROCESSING - calculate Heat Index if needed- see lecture notes for details, formula is incomplete

    double t = 0.0;
    int h = 0;

    for(n = 0; n < hI.length; n++)
    {
        if( temperature[n] >= 80.0  ) //determine if HI should be calculated, complete the condition based on Lecture notes
        {
            t = temperature[n];
            h = humidity[n];

            hI[n] = -42.379 + 2.04901523*t+ 10.1433312*h- 0.22475541*t*h- 0.000683783*(t*t)- 0.005481717* (h*h)+ 0.000122874*(h*h)*t+ 0.000085282*t*(h*h)- 0.000000199*(t*t)*(h*h);
}

原文:https://stackoverflow.com/questions/20156697
更新时间:2022-07-26 14:07

最满意答案

您可以使用getter和setter作为实现此目的的一种方法。


// our constructor function
function Color(r, g, b) {
    return {
        get red() {
            return r;
        },

        set red(value) {
            // let's make sure we get a number here
            if ( typeof value === 'number' && !isNaN(value) ) {
                // check the range
                if (value < 0) {
                    r = 0;
                } else if (value > 255) {
                    r = 255;
                } else {
                    r = value;
                }
            } else {
                // this gets set if they don't pass a number
                r = 255;
            }
        }
        // other color methods here
    };
}

// --------------------

var red = new Color(255, 0, 0);

alert(red.red); // 255

red.red -= 55;  // assignment within range, success

alert(red.red); // 200

red.red -= 999; // assignment out of range, failure

alert(red.red); // 0

red.red += 999; // assignment out of range, failure

alert(red.red); // 255

jsFiddle示例


You can use getters and setters as one way to achieve this.


// our constructor function
function Color(r, g, b) {
    return {
        get red() {
            return r;
        },

        set red(value) {
            // let's make sure we get a number here
            if ( typeof value === 'number' && !isNaN(value) ) {
                // check the range
                if (value < 0) {
                    r = 0;
                } else if (value > 255) {
                    r = 255;
                } else {
                    r = value;
                }
            } else {
                // this gets set if they don't pass a number
                r = 255;
            }
        }
        // other color methods here
    };
}

// --------------------

var red = new Color(255, 0, 0);

alert(red.red); // 255

red.red -= 55;  // assignment within range, success

alert(red.red); // 200

red.red -= 999; // assignment out of range, failure

alert(red.red); // 0

red.red += 999; // assignment out of range, failure

alert(red.red); // 255

jsFiddle example

相关问答

更多
  • 根据您的更新, 实现和签名需要稍微调整一下; inline MyEnum& operator |= (MyEnum& a, MyEnum b) // ^ here and ^ here { return a = (MyEnum)((int)a | (int)b); } 为了使操作按预期工作,重要的是签名与内置的签名相关联,并且通常会建议实现也相关联。 签名可以从注释中列出的引用中获得(在这种情况下,规范是T1& operator |= (T1& lhs, T2 ...
  • 如果您确实需要确保a只评估一次,则可以使用*=返回左值的事实: (a *= 10) += b; 但它不是很好的代码,并且我认为它可能会在C ++ 11之前调用未定义的行为,因为在不插入序列点的情况下修改a两次(一次在* =和一次在+ =)。 If you really need to make sure a is evaluated only once, you could use the fact that *= returns lvalue: (a *= 10) += b; but it's har ...
  • 不,那里没有。 简写的起源 我怀疑这个简写来自汇编语言,其中ADD指令正是这样做 - 需要两个操作数,进行添加并将其存储到第一个操作数。 我会说人们习惯这样思考,所以这种模式在C语言中也出现a += b简写。 其他语言来自C. 我认为没有特别的理由要有或没有a = a + b或a = b + a 。 我认为在编程中经常需要它们中的两个。 原因是历史性的。 与我们使用QWERTY键盘布局而不是其他键盘布局相同的原因。 更新 : 看到这一点 ,这是一个神话,因为C基于B语言,而不是来自汇编语言。 起源不明确。 ...
  • 您可以使用getter和setter作为实现此目的的一种方法。 // our constructor function function Color(r, g, b) { return { get red() { return r; }, set red(value) { // let's make sure we get a number here if ( typeof va ...
  • 您是否对拆箱转换感到困惑? 从类型Integer到int类型 从类型Double到类型double 如果r是Integer类型的引用,则取消装箱转换将r转换为r.intValue() 如果r是Double类型的引用,则取消装箱转换将r转换为r.doubleValue() 和复合赋值运算符 ? 形式E1 op= E2的复合赋值表达式等效于E1 = (T) ((E1) op (E2)) ,其中T是E1的类型,除了E1仅被评估一次。 所以这 c += a; 变 c = (int) (c + a); 在这种情况 ...
  • 所以我想如果你打破这个操作,你有: s += (s += s); s = s + (s += s); s = s + (s = s + s); // Can't actually have the "s = " part, it's really just "s + s" s = s + (s + s); s = s + s + s; 这意味着结果应该是“abcabcabc”。 So I think if you break open the operation, you have: s += ( ...
  • 请注意,在所有情况下,k的赋值都会覆盖右侧可能发生的任何增量。 在线发表评论: int k = 12; k += k++; System.out.println(k); // 24 在使用该值后, k++意味着增量,因此这与编码k = 12 + 12 k = 12; k += ++k; System.out.println(k); // 25 ++k表示在使用该值之前递增,因此这与编码k = 12 + 13 k = 12; k = k + k++ ...
  • 给你的建议是使用std::vector并且不必自己实现赋值运算符,复制构造函数和析构函数。 但话说回来,代码中有一些问题,更不用说复制构造函数了。 首先,复制构造函数应该分配一个全新的数组,并将传入值中的数组值复制到新数组中。 这是您的Student类的简化版本,只有两个成员 - 一个double *和一个表示数组中项目数的整数。 class Student { int num; double *array_d; public: Student(const Student & ...
  • 看看JLS中的行为- 复合赋值运算符 。 我在这里引用相关的两段,只是为了答案的完整性: 否则, 保存左侧操作数的值,然后评估右侧操作数。 如果此评估突然完成,则赋值表达式会出于同样的原因突然完成,并且不会发生任何分配。 否则, 左侧变量的保存值和右侧操作数的值用于执行复合赋值运算符指示的二进制运算。 如果此操作突然完成,则赋值表达式会出于同样的原因突然完成,并且不会发生任何赋值。 强调我的。 因此,首先评估左手操作数,并且仅执行一次。 然后,左手操作数的评估值(在您的情况下为1与右手操作数的结果相加,结果 ...
  • Java中有许多运算符。 但“复合比较运算符”不是其中之一。 你应该从像“Head first Java”这样的好书中阅读Java基础知识。 要回答这个特定问题, b1 |= b2是复合赋值。 =将b1|b2的结果赋给LHS操作数,即b1 。 由于现在很清楚它是一个assignment运算符而不是比较,因此b1 |= b1的结果将与b1 = b1|b1 。 (注意|这里是两个数字之间的逻辑OR而不是|| ,它是一个条件运算符。 |和||有不同的含义) HTH。 There are many operator ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。