我是 Java 编程的新手,我需要一些帮助。
这是我的问题:我们输入随机实数并希望将它们记录在矩阵中(例如[100] [100]的数组),我们输入的数字我们想查找之前是否连续输入了这样的数字,如果就是这样,我们在现场输出它们和下一个。仅当之前连续输入了数字。
这是我的代码,但很可能不正确
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]);
}
}
非常感谢 。这是有效的,但它显示了输入两次的最后一个数字。我的任务是我们输入大量数字,例如 300 或 400 数字,然后输入一个例如 23 ,我们取该数字并在霍尔矩阵中四处寻找,然后输出它(23)和前一个数字,如果它是按顺序输入的,并且仅是矩阵的下一个。例如:2,5,7,9,23,32,13,15,19,39,36,......... 3,4,9,23 输出 9,23,32 这是抓住这里。我希望你能给我指明我应该工作的方向。先感谢您 。!!!