打印未排序的数组时出现Out of Bounds错误

时间:2016-11-02 14:22:56

标签: java arrays sorting radix-sort

我对编程很新,所以我使用radix方法制作了一个数组排序器。

每次我没有未排序的数组打印语句时,我都可以打印出已排序的数组(我尝试在main方法中移动print语句无效)。

它适用于某些数字,但是2和5会失败。其他人通常会很好地工作。

我想说,虽然我是编程新手,但这不是一项家庭作业,只是为了个人利益。我更愿意得到能够让我思考而不是功能代码的答案。

感谢大家的耐心等待。我曾要求教授和TA无济于事,所以这真的是最后的手段。

这是我的代码。控制台打印"未排序的阵列"但没有数字所以错误是在我的for循环中的某个地方,但在逻辑上没有任何意义。

public static void main(String[] args) {
    String dateFormatPattern = "yyyy-MM-dd HH:mm:ss";
    String dateUtc = "2016-10-09 12:50:00";

    SimpleDateFormat dateFormatUtc = new SimpleDateFormat(dateFormatPattern);
    dateFormatUtc.setTimeZone(TimeZone.getTimeZone("UTC"));

    SimpleDateFormat dateFormatLisboa = new SimpleDateFormat(dateFormatPattern);
    dateFormatLisboa.setTimeZone(TimeZone.getTimeZone("Europe/Lisboa"));

    SimpleDateFormat dateFormatMadrid = new SimpleDateFormat(dateFormatPattern);
    dateFormatMadrid.setTimeZone(TimeZone.getTimeZone("Europe/Madrid"));

    SimpleDateFormat dateFormatParis = new SimpleDateFormat(dateFormatPattern);
    dateFormatParis.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));

    System.out.println("UTC: "+dateUtc);
    try {
        Date d = dateFormatUtc.parse(dateUtc);
        System.out.println("Lisboa: "+dateFormatLisboa.format(d));
        System.out.println("Madrid: "+dateFormatMadrid.format(d));
        System.out.println("Paris: "+dateFormatParis.format(d));
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

0 个答案:

没有答案