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.


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
    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];
                    v [r][c] =  new Double(Math.random() *10).intValue();
                    System.out.println("["+v[r]+"]" + "["+v[c]+"]");
                may = v[0][0];
                            may = v[r][c];
                    }System.out.println("El numero mayor es" + may);
    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
    My Mood
    Thanked 140 Times in 135 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 28th, 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, 01:23 PM
  4. Game 3x3
    By Koren3 in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 20th, 2009, 08:43 PM
  5. Replies: 4
    Last Post: June 10th, 2009, 01:04 AM

Tags for this Thread