Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: 3x3 array find largest number

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 3x3 array find largest number

    im making a 3x3 array filled with random numbers and im supposed to find the largest number in the array , i compiled my code and its working fine but i dont think im getting the right answer here's my code , any help will be greatly appreciated

    public class matriz_mayor{
        public static void main(String args[]){
            int  may, r, c;
            int [][] v;
            v = new int [3][3];
            for(r=0;r<=2;r++){
                for(c=0;c<=2;c++){
     
                    v [r][c] =  new Double(Math.random() *10).intValue();
     
                    System.out.println("["+v[r]+"]" + "["+v[c]+"]");
                }
                may = v[0][0];
                for(r=0;r<=2;r++){
                    for(c=0;c<=2;c++){
                        if(v[r][c]>may){
                            may = v[r][c];
                        }
                    }System.out.println("El numero mayor es" + may);
                }
            }
        }
    }run:
    [[I@190d11][[I@190d11]
    [[I@190d11][[I@a90653]
    [[I@190d11][[I@de6ced]
    El numero mayor es7
    El numero mayor es7
    El numero mayor es7
    BUILD SUCCESSFUL (total time: 0 seconds)


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: 3x3 array find largest number

    You're are seeing the toString() result from an array of int. If you want to see what v[r] holds consider using Arrays.toString(v[r]):

    // at the top:
    import java.util.Arrays;
     
        // in your for loop:
        System.out.println("[" + Arrays.toString(v[r]) + "]" + "[" + Arrays.toString(v[c]) + "]");

  3. The Following User Says Thank You to curmudgeon For This Useful Post:

    joecan2010 (November 27th, 2012)

Similar Threads

  1. [SOLVED] how to find all occurrences of a number in an array recursivelly
    By mia_tech in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 13th, 2012, 01:37 PM
  2. Find Biggest Number in Array
    By jo15765 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 12th, 2012, 03:01 PM
  3. Find the two largest number
    By vendettabf in forum What's Wrong With My Code?
    Replies: 15
    Last Post: December 29th, 2011, 12:23 PM
  4. Game 3x3
    By Koren3 in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 20th, 2009, 07:43 PM
  5. Replies: 4
    Last Post: June 10th, 2009, 01:04 AM

Tags for this Thread