更改的整数值不会出现在代码的其他部分? [英] Changed integer value doesn't show up in other parts of the code?

查看:99
本文介绍了更改的整数值不会出现在代码的其他部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉这个奇怪的标题,我真的不知道如何描述它。基本上我有一个代码,一旦调用了if语句,它就改变了整数的值, taxrate 。我认为它有效,但是一旦我尝试将其调用到代码的另一部分的JTextField中,它就会显示为0. IF语句如下:

I'm sorry for the weird title, I didn't really know how to describe it. Basically I have a code that once the if statement is called, it changed the value of the integer, taxrate. I thought it was working, but once I try to call it into a JTextField in another part of the code, it shows up as 0. The IF statement is the following:

if (taxable >= 1 && taxable <= 9075){
        taxrate = (int) (taxable * .10);
    } else if (taxable >= 9076 && taxable <= 36900) {
        taxrate = (int) (taxable * .15 + 908);
    } else if (taxable >= 36901 && taxable <= 89350) {
        taxrate = (int) (taxable * .25 + 5082);
    } else if (taxable >= 89351 && taxable <= 186350){
        taxrate = (int) (taxable * .28 + 18195);
    } else if (taxable >= 186351 && taxable <= 405100){
        taxrate = (int) (taxable * .33 + 45355);
    } else if (taxable >= 405101 && taxable <= 406750) {
        taxrate = (int) (taxable * .35 + 45883);
    } else if (taxable >= 406751) {
        taxrate = (int) (taxable * .396);
    }

taxable 由用户定义,它有在用户输入之前没有定义的值。

taxable is defined by the user, it has no defined value until the user inputs it.

推荐答案

0到10之间的任何应税值(不包括10)将给你一个税率为0,代码运作完美无缺。
如果不是这种情况,请确保在进行此比较之前实际分配了您的应税值。程序可能永远不会到达if语句中的代码块。

Any value of taxable between 0 and 10 (excluding 10) will give you a taxrate of 0 with the code working flawlessly. If this is not your case, please make sure that your taxable value is actually assigned before this comparison is made. It is possible that the program is never actually getting to the code block inside the if statement.

这篇关于更改的整数值不会出现在代码的其他部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆