Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

why this InputMismatchException ?

807599Mar 17 2007 — edited Mar 17 2007
I expected the output of the following code to be 5... Cant explain what I am doing wrong.. Code compiles but an exception is thrown an runtime..Is it perhaps the use of delimiter?
import java.util.*;
public class Test {
 
    public static void main(String[] args) {
       String csv = "Sue,5,true,3";
       Scanner scanner = new Scanner(csv);
       scanner.useDelimiter(",");
       
       int agr = scanner.nextInt(); //Throws java.util.InputMismatchException
    }
}
Thanks for any help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 14 2007
Added on Mar 17 2007
9 comments
237 views