小编com*_*umb的帖子

为什么不读取声明?

我有一个.dat文件,其中包含以下信息:

Erik 3 Rita 7 Tanner 14 Jillyn 13 Curtis 4 Stephanie 12 Ben 6
Run Code Online (Sandbox Code Playgroud)

它显示男孩的名字,男孩的年龄,女孩的名字,女孩的年龄等.

我必须计算男孩总数和女孩总数,然后加上男孩的年龄和女孩的年龄,然后找出他们之间的差异(绝对).

我创建了以下代码来执行此操作:

public class Exercise1 {
public static void main(String[] args) 
    throws FileNotFoundException {
    Scanner input = new Scanner(new File(
            "C:/FilesForJava/ChapterSixExerciseOne.dat"));
    boyGirl(input);     
}
public static void boyGirl(Scanner fileInput) {
    int boysCount = 0, girlsCount = 0, counter = 1,
            boysSum = 0, girlsSum = 0;
    while(fileInput.hasNext()){         
        if(counter % 2 != 0) {
            boysCount++;
        }
        else {
            girlsCount++;
        }
        while(fileInput.hasNextInt()) {
            if(counter % 2 != …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
91
查看次数

这个if语句是否过度杀伤?

我有一个名为Investigation的数据库表.在此表中有一列名为INV.此列可以包含值0,1或null.

在我的应用程序中,有一个如下所示的if语句:

QNet.Investigation.DataContracts.Investigation investigation = Session["InvestigationObj"] as QNet.Investigation.DataContracts.Investigation;

if (investigation != null && investigation.INV != null && investigation.INV == true)
{
    ....       
}
Run Code Online (Sandbox Code Playgroud)

在我看来,这有点矫枉过正,因为如果Investigation.INV == true,那么显然其他两个语句将不会为空.如果其他两个中的任何一个为null,那么investigation.INV也将为null.

我在这里错过了什么吗?原始开发人员是否有理由以这种方式创建if语句?岂不

if(investigation.INV == true)
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

做同样的事情?

c# if-statement

-3
推荐指数
1
解决办法
150
查看次数

标签 统计

c# ×1

if-statement ×1

java ×1