Monday 15 February 2010

java - input real numbers in two dimensional array with search for equals and output them -


I'm new to Java programming and I need some help, please

this is my question : We input random real numbers and want to record them in the matrix (for example [100] [100]), the numbers with which we want input, find them in a number that have been entered gradually before And if this happens, then we can see them and the next one The output on the sceen. Only then the number is recorded sequentially first.

Here's my code but maybe not the most correct

  import java.util.Scanner; Class addamatrix {public static zero main (string agr []) {int m, n, c, i; Scanner = new scanner (System.in); // Size of input 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 number, if we have input, then we want to assemble that end if such numbers are recorded sequentially before and if so , Then we output them and the next one Sceen only if the // numbers are recorded consecutively, respectively. For (c = in.nextin (); c & lt; m; c ++) if (array [c] []. Par (c)) System.out.println ("number is repeated" + c) ; Else System.out.println ("Enter second number"); For (d = in.nextin (); d & lt; n; d ++) array [c] [d] = in.nextInt (); If (array [c] []. Par (c)) System.out.println ("number is repeated" + c); Else System.out.println ("Enter second number"); If (array [C] [D]. Abel (C, D)); System.out.println ("The next number of inserted matrix" + array [C] [D]); }}   

Thanks a lot it is working, but it displays the last number which has the input twice. In my work we input many numbers for numbers, for example 300 or 400 numbers and for example we get 23 from an input, we take that number and go to the hall matrix and get it equally and we get it Output (23) and from the previous number if it has been entered in sequence and is only one of the next matrix. For example: 2,5,7,9,23,32,13,15,19, 39, 36, ........., 3,4, 9, 23 Output 9, 23, 32 is holding it here. I hope you should work for me to give me direction. Thank you in advance. !!!

Try this code:

  Public static zero main (string [ ] Args) {int m, n, c; Scanner = new scanner (System.in); // Size of input 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  = 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 & lt; n } {System.out.println (array [c + 1] [0]);}} Else {System.out.println (array [C] [D + 1]);}}}} In.close (); Add Comment:  
  • For loop, from 0 index to length of the array:
    • For the {0} (c = 0; c & lt; M; c ++) { and (int d = 0; d & lt; n; d ++) { <


No comments:

Post a Comment