-
June 23rd, 2013, 03:42 AM
#1
input numbers in array , find one of array and display it with privious and next one.
hello, I am a new in java programing and i want some help pls.There is my question: we input random real numbers and want to record them in the matrix (array of for example [100][100]), with that numbers we input we want to find 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. There is my code but most probably is not true!
import java.util.Scanner;
public class test {
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();
Integer prevNumber= null;
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= 0; c < m; c++) {
for (int d= 0; d < n; d++) {
array[c][d]= in.nextInt();
if (prevNumber != null && array[c][d] == prevNumber.intValue()) {
System.out.println("number is repeated" + c);
}
System.out.println("enter another number");
prevNumber= array[c][d];
}
}
in.close();
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|