Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2006

Tip: Looking for answers? Try searching our database.

throws exception won't permit compilation

Thread view: 
BillJosephson - 06 Nov 2006 08:10 GMT
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[i] = scan.nextInt();
       System.out.println( "\nReading temp from file: \t\t\t" + i +
"\t\t\t" + temperatures[i] );
    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[i] );

    // 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 - 06 Nov 2006 08:12 GMT
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.
Paul Hamaker - 06 Nov 2006 09:05 GMT
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 - 06 Nov 2006 09:13 GMT
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.
Signature

http://javalessons.com  Paul Hamaker, SEMM
Teaching ICT since 1987

BillJosephson - 06 Nov 2006 09:22 GMT
> Compilation was succesful, the exception happens when running the code.
> You forgot to indicate the comma to be the delimiter, so I guess
[quoted text clipped - 4 lines]
> http://javalessons.com  Paul Hamaker, SEMM
> Teaching ICT since 1987

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

Many many many thanks...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.