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 3 of 3

Thread: Get the lowest value from Object[][]

  1. #1
    Member
    Join Date
    Jul 2012
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Get the lowest value from Object[][]

    	public static Master generateMaster(Player player) {
    		Object[][] difference = new Object[7][7];
    		for (Master master : Master.values()) {
    			difference[master.ordinal()][0] = master;
    			difference[master.ordinal()][1] = player.getSkills().getCombatLevel() - master.getCombatLevel();
    		}
    		int lowest;
    		for (int i = 0; i < difference.length; i++) {
    			lowest = (int) difference[i][1];
    			if (((int) difference[i][1]) < lowest) {
    				lowest = (int) difference[i][1];
    				return (Master) difference[i][0];
    			}
    		}
    		return Master.VANNAKA;
    	}

    The above is my code. What I'm wanting to do is get the lowest difference in difference[i][1] and return difference[i][0] once the lowest value is found.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Get the lowest value from Object[][]

    Can you show what your code does and explain what is wrong with the results?
    You will need to post a small, complete program that compiles, executes and shows the problem for testing.

    If you have any specific questions or problems, please ask.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: Get the lowest value from Object[][]

    Quote Originally Posted by Tyluur View Post
    ...
    The above is my code. What I'm wanting to do is get the lowest ...
    A general method for your kind of task:
     
    Declare two int variables: lowest and lowestIndx
     
    Initialize the value of lowestIndex to 0
    Initialize the value of lowest to the value from element 0 of the array.
     
    Create a loop that looks at elements of the array, starting with an index value of 1
    BEGIN LOOP
        IF the array value using the current index value is less than lowest
        THEN
           Set lowest to the array value using the current index.
           Set lowestIndx to the current index value.
        END IF
    END LOOP
    //
    // After the loop do whatever you want to do with the value of lowestIndx
    //


    Cheers!

    Z
    Last edited by Zaphod_b; August 19th, 2012 at 12:24 PM.

Similar Threads

  1. [SOLVED] flightpaths, finding lowest cost -- lowest amount of crossovers
    By CjStaal in forum Algorithms & Recursion
    Replies: 4
    Last Post: May 8th, 2012, 12:47 AM
  2. Lowest Term Function Help
    By thisbeme in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 2nd, 2011, 06:33 AM
  3. Reading from ResultSet to Object and from object Object Array
    By anmaston in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 7th, 2011, 06:11 AM
  4. Replies: 1
    Last Post: December 4th, 2010, 05:26 PM
  5. Loop to note position of lowest number
    By fortune2k in forum Loops & Control Statements
    Replies: 3
    Last Post: November 23rd, 2010, 10:05 AM