File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

add numbers ot two dementional array ,check if there is equals and output it

 
Ivaylo Velev
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, I am a new in java programing and i want some help.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!




 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have gone back to your code and added code tags, which you should always use; see how much better it looks.
Avoid long lines, and multiple // comments (use /*...*/ instead) and lots of blank space.

You do not have a 2D array; there is no such thing. You have an array of arrays, which is better.
I am afraid you are writing non‑object‑oriented programming. You should have a Matrix class, and that can incorporate the array.

When you present a lot of code, I start thinking, “What algorithm did he use to create that code?” That is not obvious because you are using such short variable names “m”, for example, and the lack of {} obscures the structure of the code.
You can consider traversing the array with a pair of (nested) loops. That is one way to look for duplicates. Another way would be to put every number into a Set, and test whether the Set already contains that number before entering it into the Matrix, but that might be too advanced a topic foryou.

Suggest:
  • 1: Create a Matrix class with fields and methods
  • 2: For each action, write down on paper how you intend to do it. In whichever language you speak at home. Not in Java.
  • 3: Once you have done that, you can actually start writing some code.
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic