小编dan*_*ila的帖子

Java 1.4.2 - ArrayIndexOutOfBounds错误

(我使用的是Java 1.4.2)我希望有一个阵列可以在用户给出的一定时间内翻转"硬币"(硬币可以翻转1000次).然后随机生成1到10之间的整数,将所有数字存储在数组中.我有以下代码,但它一直给我以下错误:

线程"main"中的异常java.lang.ArrayIndexOutOfBoundsException:7在CoinFlip.main(CoinFlip.java:42)

这是我写的代码.

import java.io.*;
import java.math.*;

public class CoinFlip
{
    public static void main(String[] args) throws IOException
    {
        // setting up variables
        String timesString;
        int times;
        // setting up input
        BufferedReader in;
        in = new BufferedReader(new InputStreamReader(System.in));


        do
        {
            // times will display how many times the coin will flip
            // loop if times does not fulfill the requirements
            System.out.println("How many times do you want the coin to flip? (MUST be an integer between 1 to 1000)");
            timesString …
Run Code Online (Sandbox Code Playgroud)

java indexoutofboundsexception

-4
推荐指数
1
解决办法
107
查看次数

标签 统计

indexoutofboundsexception ×1

java ×1