Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java while循环由于未知原因正在更改预期值_Java_Arrays_While Loop - Fatal编程技术网

Java while循环由于未知原因正在更改预期值

Java while循环由于未知原因正在更改预期值,java,arrays,while-loop,Java,Arrays,While Loop,我不熟悉编码,正在为数组创建一个条件,但是我出于某种原因设置的while循环条件会在数组不应该更改的时候更改数组。如果这是显而易见的,我很抱歉,但我在这里似乎找不到适用于我的问题的问题 守则: import java.util.Scanner; //================================================================ public class ArrayIrreg { //--------------------------------

我不熟悉编码,正在为数组创建一个条件,但是我出于某种原因设置的while循环条件会在数组不应该更改的时候更改数组。如果这是显而易见的,我很抱歉,但我在这里似乎找不到适用于我的问题的问题

守则:

import java.util.Scanner;
//================================================================
public class ArrayIrreg {
//----------------------------------------------------------------
    private static Scanner Keyboard = new Scanner(System.in);

    public static void main(String[] args) {
    //----------------------------------------------------------------
        char group, rLetter;

        int num     = 10; // for test
        int rows    = 10;
        int columns =  8;

        // creating 2d array


        System.out.print("Please enter number of rows               : ");
        rows = Keyboard.nextInt();

        while (rows < 0 || rows >= 10) {
            System.out.print("ERROR:Out of range, try again              : ");
            rows = Keyboard.nextInt();
        }

        double[][] figures = new double[rows + 1][num];

        for(int t = 0; t < rows; t++) {
            rLetter = (char)((t)+(int)'A');
            System.out.print("Please enter number of positions in row " + rLetter + " : ");
            columns = Keyboard.nextInt();

            while(columns < 0 || columns >= 8) {
                System.out.print("ERROR:Out of range, try again              : ");
                columns = Keyboard.nextInt();
            }

            for(int j = 0; j <= columns; j++) {
                figures[j] = new double[j] ;
            }

        }

        // filling the array
        for(int row = 0; row < figures.length; ++row) {
            for(int col = 0; col < figures[row].length; ++col) {
                figures[row][col] = 0.0;
            }
        }

        // printing the array
        for(int row = 0; row < figures.length; ++row) {    
            // printing data row
            group = (char)((row)+(int)'A');
            System.out.print(group + " : ");

            for(int col = 0; col < figures[row].length; ++col) {    
                System.out.print(figures[row][col] + " ");
                System.out.print(" ");
            }

            System.out.println();
        }

        // printing final border
        for(int col = 0; col < figures[0].length; ++col) {
            System.out.print("-+");
        }

        System.out.println("  ");
    }
}
import java.util.Scanner;
//================================================================
公共类阵列{
//----------------------------------------------------------------
专用静态扫描仪键盘=新扫描仪(System.in);
公共静态void main(字符串[]args){
//----------------------------------------------------------------
char组,rLetter;
int num=10;//用于测试
int行=10;
int列=8;
//创建二维阵列
System.out.print(“请输入行数:”);
行=键盘.nextInt();
而(行数<0 | |行数>=10){
System.out.print(“错误:超出范围,请重试:”;
行=键盘.nextInt();
}
双精度[]位数=新的双精度[行+1][num];
for(int t=0;t=8){
System.out.print(“错误:超出范围,请重试:”;
columns=Keyboard.nextInt();
}

对于(int j=0;j您需要在每次
Keyboard.nextLine()之后调用
Keyboard.nextLine()


说明:扫描仪调用nextLine()后,它会获取第一个值,并将字符串的其余部分留给
\n
。然后,我们使用
nextLine()

时间来了解调试。打印一些内容(变量、流控制),并读取您得到的错误/堆栈跟踪。它们带有行号。使用实际的调试器可能会有些过火,但学习起来也非常有用。这似乎对我很有用。您能比返回时出现不同错误或显示错误数量更具体些吗?