import java.text.*;
import java.io.*;

public class Assignment9
{
    public static double findMin(double[] numbers, int startIndex, int endIndex)
    {
        if (startIndex == endIndex) return numbers[startIndex];
            else
            {
                double prevMin = findMin(numbers, startIndex, endIndex-1);
                if (prevMin>numbers[endIndex])
                    return numbers[endIndex];
                else
                    return prevMin;
            }
    }

    public static double computePositiveSum(double[] numbers, int startIndex, int endIndex)
    {
        if (startIndex == endIndex && startIndex>0) return numbers[startIndex];
            else
            {
                double prevSum = computePositiveSum(numbers, startIndex, endIndex-1);
                if (0<numbers[endIndex])
                    return numbers[endIndex]+prevSum;
                else
                    return prevSum;
            }
    }

    public static double computeSumAtOdd(double[] numbers, int startIndex, int endIndex)
    {
        if (startIndex == endIndex) return 0;
            else
            {
                double prevSum = computeSumAtOdd(numbers, startIndex, endIndex-1);
                if (0 != numbers[endIndex]%2)
                    return numbers[endIndex]+prevSum;
                else
                    return prevSum;
            }
    }
    public static int countNegative(double[] numbers, int startIndex, int endIndex)
    {
        if (startIndex == endIndex && startIndex>0) return 0;
            else
            {
                double Count = countNegative(numbers, startIndex, endIndex-1);
                if (0>numbers[endIndex])
                    return (int)Count++;
                else
                    return (int)Count;
            }
    }
  public static void main (String[] args)
   {
       try {
         BufferedReader in = new BufferedReader(new FileReader(filename));
         double a[] = new double[100];
         int b=0;
         while((a[b] = in.readArray()) != null && in.readDouble() !=0) {  // Read line, check for end-of-file
           a[b] = in.readArray();              // Print the line
         }
         in.close();    // Always close a stream when you are done with it
       }
catch (IOException e) {
    system.out.println("File Not Found");
}
system.out.println("The minimum number is" + findMin(a, 0, a.getLength()));
system.out.println("The sum of the positive numbers is" + computePositiveSum(a, 0, a.getLength()));
system.out.println("The sum of the numbers at odd indexes is" + computeSumAtOdd(a, 0, a.getLength()));
system.out.println("The total count of negative numbers is" + countNegative(a, 0, a.getLength()));
}
}

This is just the base of what I have. Im having a lot of trouble when it gets to writing the array from the input file.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

What sort of error are you getting??

As for me, im reading text files using Strings. Then I manipulate these Strings into whatever I want. Its just my suggestion.

What are you trying to do? What do you expect to happen when you run this particular piece of code? What happens instead?
If you want people to help you, make it easy for them - tell them what the problem is.
This is also helpful for you, since it often turns out that stating a problem clearly leads you to a solution.


Code tags would also be handy, for legibility.

This article has been dead for over six months. Start a new discussion instead.