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: Error "; needed"

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Error "; needed"

    So my code is just about finished for a project I have due tomorrow. However there's one part that's still preventing the code from being compiled completely. Here's the error it returns.

    Paniagua_ArrayProcessing.java:108: ';' expected
            public static void evenOdd(int[] array) throwsIOException{
                                                   ^
    1 error

    And here's the full code. I've looked it over for semicolons and brackets but nothing appears to be wrong. I don't know what I could or should do. Any help is appreciated. Thanks!

    import java.io.*;
    import java.util.Scanner;
    public class Paniagua_ArrayProcessing{
            //The main method: arranges all operations.
            public static void main(String[] args) throws IOException{
                    int[] numbers = inputData();
                    printArray(numbers);
                    reverseArray(numbers);
                    int arraySum = sum(numbers);
                    System.out.println("The sum of all elements is: " + arraySum);
                    double arrayMean = mean(numbers);
                    System.out.printf("The mean of all elements is: %.2f\n", arrayMean);
                    int arrayMin = min(numbers);
                    System.out.println("The min of all the elements is: " + arrayMin);
                    int arrayMax = max(numbers);
                    System.out.println("The max of all the elements is: " + arrayMax);
                    evenOdd(numbers);
                    System.out.println("Program completed. Data written to the files.");
            }
            //inputData method: gathers data and creates array.
            public static int[] inputData() throws IOException{
                    Scanner keyboard = new Scanner(System.in);
                    String input;
                    int lines;
                    System.out.println("Please enter a file name: ");
                    input = keyboard.nextLine();
                    File myfile = new File(input);
                    if (!myfile.exists()){
                            System.out.println("File not found.");
                            System.exit(1);
                    }
                    Scanner inputFile = new Scanner(myfile);
                    lines = inputFile.nextInt();
                    int[] numbers = new int[lines];
                    for (int i=0; i<lines; i++){
                            if (inputFile.hasNextInt()){
                                    int moreLines = inputFile.nextInt();
                                    numbers[i] = moreLines;
                            }
                    }
                    inputFile.close();
                    return numbers;
            }
            //printArray method: prints arrays.
            public static void printArray(int[] array){
                    System.out.println("Printing array: ");
                    for (int i = 1; i<array.length+1; i++){
                            System.out.printf("%7d", array[i-1]);
                            if (i%10==0){
                                    System.out.println();
                            }
     
                    }
                    System.out.println();
            }
            //reverseArray method: prints reversed arrays.
            public static void reverseArray(int[] array){
                    System.out.println("Printing reversed array: ");
                    int a=0;
                    for (int i = array.length-1; i>=0; i--){
                            System.out.printf("%7d", array[i]);
                            a++;
                            if (a%10==0){
                                    System.out.println();
                            }
                    }
                    System.out.println("\n");
            }
            //sum method: adds all elements of an array.
            public static int sum(int[] array){
                    int total = 0;
                    for (int i = 0; i < array.length; i++){
                            total += array[i];
                    }
                    return total;
            }
            //mean method: This method hurts everyone. JK, it calculates the average of an array.
            public static double mean(int[] array){
                    double total = 0;
                    double average;
                    for (int i = 0; i < array.length; i++)
                    total += array[i];
                    average = total / array.length;
                    return average;
            }
            //min method: calculates the lowest number in an array.
            public static int min(int[] array){
                    int lowest = array[0];
                    for (int i = 1; i < array.length; i++){
                            if (array[i] < lowest){
                                    lowest = array[i];
                            }
                    }
                    return lowest;
            }
            //max method: calculates the highest number in an array.
            public static int max(int[] array){
                    int highest = array[0];
                    for (int i = 1; i < array.length; i++){
                            if (array[i] > highest){
                                    highest = array[i];
                            }
                    }
                    return highest;
            }
            // evenOdd method: writes odd or even numbers to their files respectively.
            public static void evenOdd(int[] array) throwsIOException{
                    PrintWriter outputFileEven = new PrintWriter("even.out.txt");
                    PrintWriter outputFileOdd = new PrintWriter("odd.out.txt");
                    for (int i = 0; i<array.length; i++){
                            if (array[i] % 2 ==0){
                                    outputFileEven.println();
                            }
                            else{
                                    outputFileOdd.println();
                            }
                    }
                    outputFileEven.close();
                    outputFileOdd.close();
            }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,476
    My Mood
    Mellow
    Thanks
    151
    Thanked 609 Times in 596 Posts

    Default Re: Error "; needed"

    You need a space space between throws and IOException.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    deejaypanininini (March 16th, 2014)

  4. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Error "; needed"

    Wowwwwwwww. Thanks a lot!

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,476
    My Mood
    Mellow
    Thanks
    151
    Thanked 609 Times in 596 Posts

    Default Re: Error "; needed"

    You're welcome.

Similar Threads

  1. "Error cannot find symbol" "throws BadLocationException"
    By coltson in forum AWT / Java Swing
    Replies: 1
    Last Post: June 30th, 2013, 10:33 PM
  2. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  3. Replies: 1
    Last Post: April 7th, 2013, 03:40 PM
  4. Replies: 3
    Last Post: December 7th, 2011, 01:03 AM
  5. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM

Tags for this Thread