java - 数数不存在的东西?

标签 java math count bluej

当我编译它并输入 5 个偶数或 5 个奇数时,计数结果为 6 个偶数和 1 个奇数或 6 个奇数和 1 个偶数。我想我做的一切都是对的,请帮忙,明天晚上就到期了。抱歉,我现在写这篇文章只是为了提交它。

    String oneString="";
    String twoString="";
    String threeString="";
    String fourString="";
    String fiveString="";

    int evenCount = 0, oddCount = 0, zeroCount = 0;

    oneString = JOptionPane.showInputDialog ("Input your first number");
    one = Integer.parseInt (oneString);
    while (one > 0) {
    one = one % 10;
    if (one%2==0) 
    {
       evenCount++;
    }
    else 
    { 
       oddCount++;
    }
    one = one / 10;
   }
   twoString = JOptionPane.showInputDialog ("Input your second number");
    two = Integer.parseInt (twoString);

   while (two > 0) {
    two = two % 10;
    if (two%2==0) 
    {
       evenCount++;
    }
    else 
    { 
       oddCount++;
    }
    two = two / 10;
   }
   threeString = JOptionPane.showInputDialog ("Input your third number");
    three = Integer.parseInt (threeString);

   while (three > 0) {
    three = three % 10;
    if (three%2==0) 
    {
       evenCount++;
    }
    else 
    { 
       oddCount++;
    }
    three = three / 10;
   }
   fourString = JOptionPane.showInputDialog ("Input your fourth number");
    four = Integer.parseInt (fourString);
   while (four > 0) {
    four = four % 10;
    if (four%2==0) 
    {
       evenCount++;
    }
    else 
    { 
       oddCount++;
    }
    four = four / 10;
   }
   fiveString = JOptionPane.showInputDialog ("Input your fifth number");
    five = Integer.parseInt (fiveString);
    while (five > 0) 
   {
        five = five % 10;
        if (five%2==0) 
        {
           evenCount++;
        }
        else 
        { 
            oddCount++;
        }
        five = five / 10;
   }
   float count;
   count = evenCount++ + oddCount++;
   System.out.println(); 
   System.out.printf("Even: %d Odd: %d",evenCount, oddCount);
   float percentage;
   percentage = evenCount * 100 / count;
   System.out.println(" Percentage  of Even " + percentage);
   float oddpercentage;
   oddpercentage = oddCount * 100 / count;
   System.out.println(" Percentage  of Odd " + oddpercentage);

最佳答案

我猜你的问题就在这里:

计数 = 偶数计数++ + 奇数计数++;

关于java - 数数不存在的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21057700/

相关文章:

Java > 8 stream 同时统计多个项目

java - 如何遍历 Java 列表并检查它是否等于多个字符串?

java - Hibernate 无法解析属性

objective-c - 如何计算圆圆周上点的(x或y)坐标?

python - 在二维中扩展 numpy 数组的最简单方法是什么?

math - 云的算法

python - 计算一行中符合条件的值 - Python

java - Java中的多个爬虫数据库连接

java - JTable 中的项目始终处于选中状态

mysql - 在 MySQL 查询中显示零计数