Missing value in Java

后端 未结 11 2751
慢半拍i
慢半拍i 2021-02-20 11:51

What is the statement that can be used in Java to represent a missing value of a variable. for instance I want to write a code:

if (a>=23)
 income = pay_rate;         


        
11条回答
  •  不知归路
    2021-02-20 12:10

    you could try this as well, maybe just the way I like to do it, but up to you :p

    if(a >= 23){
        income = payRate;
    } else{
        income = null;
    }
    

    rather than setting it to null by default, you set it to null after it checks what a is. also, make sure income is either an Integer or Double

提交回复
热议问题