Results 1 to 4 of 4
  1. #1
    faust83 is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Question Finding Min value in an Array

    I'm having an issue declaring the parameter in the main class to use the method getMinValue in my array class.

    I hope you an help me out!

    thanks in advance...

    Main app:

    Java Code:
     System.out.println("The minimin value in array A is: " +getMinValue(?????));

    Array Class:

    Java Code:
    
       private int [] v; 
        
        public Data(int m)
        {
            v=new int [m];
        }
        
    
      public static int getMinValue(int[] v){  
               
             int minValue = v[0];  
          
             for(int i=1;i<v.length;i++){ 
                 
             if(v[i] < minValue){  
                 
               minValue = v[i];  
               
             }  
           }  
           
             return minValue;  
           }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Finding Min value in an Array

    You have already declared the argument: it is the array v. Or if you want to call it with some other argument, declare that other array the same way you declare v. Don't forget to put some values into the array if you want it to do something useful.

  3. #3
    heman is offline Member
    Join Date
    Aug 2012
    Posts
    39
    Rep Power
    0

    Default Re: Finding Min value in an Array

    Quote Originally Posted by faust83 View Post
    I'm having an issue declaring the parameter in the main class to use the method getMinValue in my array class.

    I hope you an help me out!

    thanks in advance...

    Main app:

    Java Code:
     System.out.println("The minimin value in array A is: " +getMinValue(?????));

    Array Class:

    Java Code:
    
       private int [] v; 
        
        public Data(int m)
        {
            v=new int [m];
        }
        
    
      public static int getMinValue(int[] v){  
               
             int minValue = v[0];  
          
             for(int i=1;i<v.length;i++){ 
                 
             if(v[i] < minValue){  
                 
               minValue = v[i];  
               
             }  
           }  
           
             return minValue;  
           }
    i think,here is solution:


    here x[] is an array of integers

    int min=x[0];
    for(int j=0;j<x.length;j++)
    {
    while(x[j]<min)
    {
    min=x[j];
    }

    }

    regards,
    heman

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Finding Min value in an Array

    Java Code:
    int min=x[0];
    for(int j=0;j<x.length;j++)
    {
    while(x[j]<min)
    {
    min=x[j];
    }
    
    }
    if x is empty and has a size of 0, then the for loop would loop from 0 to 0, in other words, not at all.

Similar Threads

  1. Help finding sum of an array
    By HalfAZN in forum New To Java
    Replies: 15
    Last Post: 04-23-2012, 06:29 PM
  2. Finding a string in an array.
    By rokit boy in forum New To Java
    Replies: 8
    Last Post: 03-18-2012, 07:38 AM
  3. Finding Mode of an array
    By nfill14 in forum New To Java
    Replies: 0
    Last Post: 02-13-2012, 11:51 PM
  4. Algorithm for finding max and min in an array.
    By Shyamz1 in forum New To Java
    Replies: 4
    Last Post: 10-04-2011, 11:45 PM
  5. Finding the Mode in An Array
    By carlodelmundo in forum New To Java
    Replies: 23
    Last Post: 10-31-2010, 01:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •