如果声明,如何将字符串中的值分配给数组?

时间:2018-09-27 23:59:42

标签: java

如果有陈述,如何将字符串中的值分配给数组。当我使用for循环时,我得到的是空值。在此程序中,用户输入框数,然后减去最大值。到目前为止,这是我一直在努力的工作。谢谢

    System.out.println("Enter the number of boxes");
    boxes[i] = keyboard.nextInt();
    keyboard.nextLine();
    i++;


    for(l = 0;l < boxes.length;l++) {

    calcBoxes = boxes[l];

    number = maxBoxes - calcBoxes;

        for(m = 0; m < strangeBox.length;m++){

        if (number >=1 && number <=33){
            trikDescription = "Rabbit";
            numberDesc[m]= trikDescription;
            m++;


        }
        else if(number >=34 && number <=66) {
            trikDescription = "Tired lion";
            numberDesc[m]= trikDescription;
            m++;

    }
        else if(number >=67 && number <=88) {
            trikDescription = "Pink Zebra";
            numberDesc[m]= trikDescription;
            m++;
    }
        else if (number >=89 && number <=100) {
            trikDescription = "Drunk Monkey";
            numberDesc[m]= trikDescription;
            m++;
    }
        else if(number >100) {
            trikDescription = "Simba";  
            numberDesc[m]= trikDescription;
            m++;

    }

  }

1 个答案:

答案 0 :(得分:0)

缺少太多代码,无法准确查明问题所在

  

如果有陈述,则从字符串到数组内部的值

您在说什么价值?如果是哪个语句?什么数组?

`calcBoxes =盒子[l];

number = maxBoxes - calcBoxes;

    for(m = 0; m < strangeBox.length;m++)`

变量“ calcBoxes”,“ maxBoxes”和“ strangeBox”从何而来? 您在声明变量吗?

System.out.println("Enter the number of boxes");
boxes[i] = keyboard.nextInt();
keyboard.nextLine();
i++;

这应该是一个循环吗?你为什么要“ i ++”