throws exception won't permit compilation

Discussion in 'Java' started by BillJosephson, Nov 6, 2006.

  1. Hello, I get the general output errors;

    --------------------Configuration: <Default>--------------------


    public class monthTempsClient
    {
    public static void main( String [] args ) throws IOException
    {
    int belowFreezing = 0;
    int above100 = 0;
    int[] temperatures = new int [30];
    int i = 0;
    int bigChange = 0;
    File tempsFile = new File( "tempsFile.csv" );
    Scanner scan = new Scanner( tempsFile );

    while (scan.hasNext ())
    {
    temperatures = scan.nextInt();
    System.out.println( "\nReading temp from file: \t\t\t" + i +
    "\t\t\t" + temperatures );
    i ++;
    }

    // make month
    monthTemps aprilTemps = new monthTemps ( temperatures );
    System.out.println( aprilTemps.toString( ) );

    // make another month same as first
    monthTemps marchTemps = new monthTemps( temperatures );
    System.out.println( marchTemps.toString( ) )

    // are months equal?
    if ( aprilTemps.equals( marchTemps ) )
    System.out.println( "\nThe two months have equal temps\n"
    );
    else
    System.out.println( "\nThe two months do not have equal
    temps\n" );

    // get temperatures
    temperatures = aprilTemps.getTemps( );
    System.out.println( "\nApril temperatures: " );
    for (i = 0; i < temperatures.length; i++)
    System.out.println( "\n " + i + " temperature: " +
    temperatures );

    // change month's temps
    marchTemps.setTemps( temperatures );

    // are months equal now?
    if ( aprilTemps.equals( marchTemps ) )
    System.out.println( "\nThe two months have equal temps\n" );
    else
    System.out.println( "\nThe two months have different temps\n"
    );

    // get month's biggest temp change
    bigChange = marchTemps.biggestChange( );
    System.out.println( "\nThe biggest daily change is " + bigChange
    );

    // how many > .300 hitters on the home team?
    belowFreezing = aprilTemps.belowFreezing( );
    System.out.println( "\n " + belowFreezing + " temps were under
    freezing" );

    // how many total hits does the home team have?
    above100 = aprilTemps.above100( );
    System.out.println( "\nThe month has " + above100 + " days above
    100 degrees." );
    }
    }


    I do have a csv file with integer values separated by commas.

    Thanks.....
    BillJosephson, Nov 6, 2006
    #1
    1. Advertising

  2. My apologies, somehow I left out the error message:


    --------------------Configuration: <Default>--------------------
    Exception in thread "main" java.util.InputMismatchException
    at java.util.Scanner.throwFor(Scanner.java:819)
    at java.util.Scanner.next(Scanner.java:1431)
    at java.util.Scanner.nextInt(Scanner.java:2040)
    at java.util.Scanner.nextInt(Scanner.java:2000)
    at monthTempsClient.main(monthTempsClient.java:25)

    Process completed.
    BillJosephson, Nov 6, 2006
    #2
    1. Advertising

  3. BillJosephson

    Paul Hamaker Guest

    Compilation was succesful, the exception happens when running the code.
    You forgot to indicate the comma to be the delimiter, so I guess
    something like this would solve it
    scanref.useDelimiter("\\s*,\\s*");
    // use a comma as delimiter, possibly flanked by whitespace.
    --
    http://javalessons.com Paul Hamaker, SEMM
    Teaching ICT since 1987
    Paul Hamaker, Nov 6, 2006
    #3
  4. BillJosephson

    Paul Hamaker Guest

    Compilation was succesful, the exception happens when running the code.
    You forgot to indicate the comma to be the delimiter, so I guess
    something like this would solve it
    scan.useDelimiter("\\s*,\\s*");
    // use a comma as delimiter, possibly whitespace on either side.
    --
    http://javalessons.com Paul Hamaker, SEMM
    Teaching ICT since 1987
    Paul Hamaker, Nov 6, 2006
    #4
  5. Paul Hamaker wrote:
    > Compilation was succesful, the exception happens when running the code.
    > You forgot to indicate the comma to be the delimiter, so I guess
    > something like this would solve it
    > scan.useDelimiter("\\s*,\\s*");
    > // use a comma as delimiter, possibly whitespace on either side.
    > --
    > http://javalessons.com Paul Hamaker, SEMM
    > Teaching ICT since 1987



    WOW, that did it!!! Thank you SO MUCH !

    Many many many thanks...
    BillJosephson, Nov 6, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Miller
    Replies:
    4
    Views:
    13,284
    Chris Smith
    Nov 22, 2003
  2. Lighter
    Replies:
    3
    Views:
    399
    noone
    Aug 10, 2006
  3. Replies:
    0
    Views:
    384
  4. Replies:
    3
    Views:
    478
    andn01
    Oct 1, 2008
  5. gst
    Replies:
    10
    Views:
    390
Loading...

Share This Page