Java 在二维数组中输入实数,搜索等于并输出它们

Java 在二维数组中输入实数,搜索等于并输出它们,java,Java,我是Java编程新手,我需要一些帮助 这是我的问题:我们输入随机实数,并希望将它们记录在矩阵中(例如[100][100]的数组),我们输入的数字希望找到之前是否有连续输入的此类数字,如果是这样,我们在sceen输出它们和下一个数字。仅当之前连续输入了数字时 这是我的代码,但很可能是不正确的 import java.util.Scanner; class AddAMatrix { public static void main(String args[]) { int m

我是Java编程新手,我需要一些帮助

这是我的问题:我们输入随机实数,并希望将它们记录在矩阵中(例如[100][100]的数组),我们输入的数字希望找到之前是否有连续输入的此类数字,如果是这样,我们在sceen输出它们和下一个数字。仅当之前连续输入了数字时

这是我的代码,但很可能是不正确的

import java.util.Scanner;

class AddAMatrix {
    public static void main(String args[]) {
        int m, n, c, i;
        Scanner in = new Scanner(System.in);
        //input the size of the matrix
        System.out.println("Enter the number of rows and columns of matrix");
        m = in.nextInt();
        n  = in.nextInt();

        int array[][] = new int[m][n];

        System.out.println("Enter number");
        //we input random numbers and want to record them in the matrix, with that numbers we input we want to fing if there are 
        //such a numbers entered before successively and if that is so , we output them and the next one at the sceen . only if the 
        //numbers are successively entered before.
        for (c = in.nextin(); c < m; c++)
            if (array[c][].equals(c))
                System.out.println("number is repeated" + c);
            else System.out.println("enter another number");
        for (d = in.nextin(); d < n ;d++ )
            array[c][d] = in.nextInt();
        if (array[c][].equals(c))
            System.out.println("number is repeated" + c);
        else System.out.println("enter another number");

        if (array[c][d].equals(c, d));
        System.out.println("next number of entered matrix is" + array[c][d]);                  
    }
}
import java.util.Scanner;
类AddAMatrix{
公共静态void main(字符串参数[]){
int m,n,c,i;
扫描仪输入=新扫描仪(系统输入);
//输入矩阵的大小
System.out.println(“输入矩阵的行数和列数”);
m=in.nextInt();
n=in.nextInt();
int数组[][]=新的int[m][n];
System.out.println(“输入编号”);
//我们输入随机数,并希望将它们记录在矩阵中,用我们输入的数字来判断是否存在
//这样的数字在之前连续输入,如果是这样,我们在sceen输出它们和下一个
//之前连续输入数字。
对于(c=in.nextin();c


非常感谢。这是可行的,但它显示了最后输入两次的数字。我的任务是我们输入大量的数字,例如300或400个数字,然后输入一个,例如23,我们取那个数字,在霍尔矩阵中循环,找到相等的数字,然后输出它(23)和前一个数字,如果它是按顺序输入的,则只输出矩阵中的下一个。例如:2,5,7,9,23,32,13,15,19,39,36。我希望你能给我工作的方向。提前谢谢你

请尝试以下代码:

public static void main(String[] args) {
    int m, n, c;
    Scanner in= new Scanner(System.in);
    //input the size of the matrix
    System.out.println("Enter the number of rows and columns of matrix");
    m= in.nextInt();
    n= in.nextInt();

    int array[][]= new int[m][n];

    for (c= 0; c < m; c++) {
        for (int d= 0; d < n; d++) {
            array[c][d]= in.nextInt();
        }
    }

            System.out.println("Enter a number to search for:");
            int queryNum= in.nextInt();

            //search for it
    for (c= 0; c < m; c++) {
        for (int d= 0; d < n; d++) {
            if (array[c][d] == queryNum) {
                if (d == 0) {
                    if (c - 1 >= 0) {
                        System.out.println(array[c-1][n-1]);
                    }
                } else {
                    System.out.println(array[c][d+1]);
                }
                System.out.println(array[c][d]);
                if (d + 1 >= n) {
                    if (c+1 < n) {
                        System.out.println(array[c+1][0]);
                    }
                } else {
                    System.out.println(array[c][d+1]);
                }
            }
        }
    }


    in.close();
}
publicstaticvoidmain(字符串[]args){
int m,n,c;
扫描仪输入=新扫描仪(系统输入);
//输入矩阵的大小
System.out.println(“输入矩阵的行数和列数”);
m=in.nextInt();
n=in.nextInt();
int数组[][]=新的int[m][n];
对于(c=0;c=0){
System.out.println(数组[c-1][n-1]);
}
}否则{
System.out.println(数组[c][d+1]);
}
System.out.println(数组[c][d]);
如果(d+1>=n){
如果(c+1
几句话:

  • 在for循环中,从0索引迭代到数组的长度:
    • for(c=0;c
      for(int d=0;d
  • 您必须始终关闭正在使用的流(中的扫描仪),就像我在最后一行中所做的那样

非常感谢。这是可行的,但它显示了最后输入两次的数字。我的任务是我们输入很多数字,例如300或400个数字,然后再输入一个数字,例如23,我们接受这个数字。对不起,我不明白您的要求是什么。我们已经输入了很多数字,下一个输入的数字之一必须找到是否输入了d在我们的矩阵中之前如果是这样,我们取矩阵的上一个和下一个,并将它们全部显示在树中。尝试更新的代码。没有尝试过,但逻辑应该是好的。我尝试过,它是好的,但我不知道如何准确地做这项工作。