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

Thread: Show minimum value

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Show minimum value

    public static void main(String[] args) {
    int arr[]=new int[5];

    Scanner in=new Scanner (System.in);
    System.out.println("enter the array");
    for(int i=0;i<arr.length;i++)
    arr[i]=in.nextInt();
    int c =differenceBetween(arr);
    System.out.println("output"+c);
    }
    public static int differenceBetween(int arr[])
    {int max=0,min=0,c;
    for(int i=0;i<arr.length;i++)
    {
    if(arr[i]>max)

    max=arr[i];



    else if(arr[i]<min)

    min=arr[i];


    }System.out.println("check minimum"+min);
    return c=max-min;
    }
    }


    iam newbie in java..so help me out from this problem..it is not showing the minimum value


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default re: Show minimum value

    Please post your code using code or highlight tags as explained near the top of this topic.

    Give your threads meaningful titles.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Show minimum value

    A technique when searching an array for a max (or min) value is to set the max (or min) variable to the first element in the array and then compare all the rest of the elements against what is in max (or min) and swap as found.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Sep 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Show minimum value

    Oh i got it...thnks

Similar Threads

  1. Replies: 2
    Last Post: February 18th, 2014, 06:20 PM
  2. Help with method. Finding minimum value in Array
    By richardman54 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 31st, 2013, 11:13 PM
  3. Minimum Spanning Tree
    By Undertaker in forum Algorithms & Recursion
    Replies: 1
    Last Post: March 17th, 2012, 09:47 AM
  4. Beginner: Show Image in Label when Results Show Up
    By Big Bundy in forum Java Theory & Questions
    Replies: 3
    Last Post: April 4th, 2011, 02:43 PM
  5. Minimum value of objects in ArrayList
    By Sputnik in forum Loops & Control Statements
    Replies: 2
    Last Post: October 23rd, 2010, 01:20 PM