Note that there are some explanatory texts on larger screens.

plurals
  1. POEntering negative Numbers on Array
    primarykey
    data
    text
    <p>I am running an array that is based on a number input. It uses recursion to find the min number on the array. If the user enters 0 the program ends. It works fine until I deal with negative numbers let say I enter 0 2 3 5 3. The return comes correctly the lowest number would be 0. However If I enter 2 9 92 2 -1 0. The program does not end once I enter the 0 thusly it does not show -1 as the min number. Any suggestions or help. </p> <pre><code> import java.io.*; import java.text.*; public class Assignment9 { public static void main (String args[]) throws IOException { int i = 0; double[] NumArray; NumArray = new double[100]; // input stream reader reads in keyboard inputs, while buffered reader // reads in the line as a string15. InputStreamReader inRead = new InputStreamReader(System.in); BufferedReader buffRead = new BufferedReader(inRead); String line = buffRead.readLine(); // if the string is equal to 0 and is false AND i is less than22. // 100, parse string into double.23. try { while (line.equals("0") == false &amp;&amp; i&lt;100) { i++; line = buffRead.readLine(); NumArray[i]=Double.parseDouble(line); } } catch(IOException e) { System.out.println("Array index out of bound"); } double min = findMin(NumArray, 0, NumArray.length - 1); System.out.print ("The minimum number is " + min + ('\n')); public static double findMin(double[] NumArray, int startIndex, int endIndex) { if (startIndex == endIndex) { return NumArray[startIndex]; } else if(findMin(NumArray, startIndex, endIndex - 1) &lt; NumArray[endIndex]) { return findMin(NumArray, startIndex, endIndex -1 ); } else { return NumArray[endIndex]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload