我的数组代码显示没有输出,我的错误/缺乏

时间:2017-04-30 09:32:06

标签: java arrays

对于java basic的练习,我们的讲师告诉我们使用Arrays,询问用户10个整数然后输出偶数,奇数和所有数字的总和。不知怎的,我的代码只显示0,我缺少一些代码还是有错误?

import java.lang.System;
import java.lang.String;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;

public class ARRAY
{
    public static void main (String[]args)
    {
        String fire;
        int counter, value, clock, even, odd, number, total;
        int userArray[] = new int[20];
        int evenArray[] = new int[20];
        int oddArray[] = new int[20];

        JTextArea area = new JTextArea(10,10);

        even = 0;
        odd = 0;
        total = 0;

        for(counter = 0; counter < 10; ++counter)
        {
            fire = JOptionPane.showInputDialog(null,"Enter Array ["+ counter + "]:");
            value = Integer.parseInt(fire);
            userArray[counter] = value;
        }

        for(clock = 0; clock < 10; ++clock);
        {
            number = userArray[clock];
            total = total + number;

            if(number%2 == 0)
            {
                evenArray[even] = number;
                ++even;
            }

            if(number%2 != 0)
            {
                oddArray[odd] = number;
                ++odd;
            }
        }

        area.append("The even numbers are :");
        for(counter = 0; counter < even; ++counter)
        {
            area.append(" " +evenArray[counter]);
        }

        area.append("\nThe odd numbers are :");
        for(counter = 0; counter < odd; ++counter)
        {
            area.append(" " +oddArray[counter]);
        }

        area.append("\nThe sum of all numbers is: "+total);

        JOptionPane.showMessageDialog(null,area);

        System.exit(0);

    }
}

感谢每一个帮助! 感谢。

1 个答案:

答案 0 :(得分:2)

这是逻辑,您必须在for:

之后删除;
for (clock = 0; clock < 10; ++clock); 
//----------------------------------^

for的平均结束,{}之间的阻塞是无用的。