Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

throws exception won't permit compilation

0 views
Skip to first unread message

BillJosephson

unread,
Nov 6, 2006, 3:10:18 AM11/6/06
to
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

unread,
Nov 6, 2006, 3:12:02 AM11/6/06
to
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

unread,
Nov 6, 2006, 4:05:01 AM11/6/06
to
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

unread,
Nov 6, 2006, 4:13:54 AM11/6/06
to
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.

BillJosephson

unread,
Nov 6, 2006, 4:22:19 AM11/6/06
to


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

Many many many thanks...

0 new messages