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: Finding the lowest integer using sentinellvalue. :( I am stuck!

Threaded View

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Finding the lowest integer using sentinellvalue. :( I am stuck!

    Hello All,

    I am trying to find the lowest integer. I want the user to enter a set of integers and then have the user enter a value to exit the program and have the lowest integer display.

    So far, I have the user enter 4 integers and for the fifth integer, the user enters -1. The lowest integer displays.

    But what if the user wants to enter 3 integers and have the lowest display?

    I don't know what to do in order to make this program work I have sat here at my PC for hours trying to plug in IF statements but nothing works.. ugh!

    Here is my code so far:




    import java.util.Scanner;
    public class Lowjb
    {
    	public static void main(String [] args)
    	{
    		double num1;
    		double num2;
    		double num3;
    		double num4;
    		double num5= 0;
    		double numberCounter;
     
    		numberCounter = 0;
     
    		Scanner input = new Scanner(System.in);
     
    		while(num5!=-1)
    		{
    		System.out.println("Please enter your first number or enter -1 to exit: " );
    		num1 = input.nextDouble();
     
    		System.out.println("Please enter your second number or enter -1 to exit: " );
    		num2 = input.nextDouble();
     
    		System.out.println("Please enter your third number or enter -1 to exit: " );
    		num3 = input.nextDouble();
     
    		System.out.println("Please enter the fourth number or enter -1 to exit: " );
    		num4 = input.nextDouble();
     
    		System.out.println("Please enter the fifth number or enter -1 to exit: " );
    		num5 = input.nextDouble();
     
     
    		double result = minimum(num1, num2, num3, num4);
    		System.out.println("The minimum value of the group of numbers is: " + result);
     
    		numberCounter = numberCounter+1;
    		}
    	}
     
    	public static double minimum(double a, double b, double c, double d)
    	{
    		double minimumValue = a;
     
    		if(b < a)
    			minimumValue = b;
     
    		if(c < a)
    			minimumValue = c;
     
    		if(d < a)
    			minimumValue = d;
     
    		return minimumValue;
     
    	}
    }
    Last edited by Norm; March 7th, 2013 at 08:12 AM. Reason: zero change to letter O


Similar Threads

  1. Finding the lowest number in an array.
    By EatMyBible in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 4th, 2013, 02:49 AM
  2. Finding a Smallest Integer
    By antnas in forum Collections and Generics
    Replies: 5
    Last Post: November 1st, 2012, 01:15 AM
  3. Get the lowest value from Object[][]
    By Tyluur in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 19th, 2012, 10:55 AM
  4. [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
  5. Finding the range of 2 integer inputs
    By dunnage888 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 1st, 2012, 03:54 PM