permaculture playing cards*
The moose likes Beginning Java and the fly likes Problem with scanner class execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with scanner class execution" Watch "Problem with scanner class execution" New topic
Author

Problem with scanner class execution

sandeep patrudu
Greenhorn

Joined: Feb 22, 2007
Posts: 6
Hi Everyone,
i got problem with scanner class it was compiling with no errors but it is thrown an Input MisMatch exception when excuting and the code is given below.

import java.util.*;
public class practiseQ142{
public static void main(String args[]){
String ip="10,23,65";
Scanner src=new Scanner(ip);
src.useDelimiter(" , ");
int a=0;
while(src.hasNext()){
a+=src.nextInt(); }
System.out.println(a);
}
}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
Please use "code" tags around quoted code.

You are using the wrong delimiter. You are not using comma as you think, but space-comma-space.
sandeep patrudu
Greenhorn

Joined: Feb 22, 2007
Posts: 6
Hi Ritchie,

Thanks for helping me on this
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
You're welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with scanner class execution