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; } }