File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 36514
    
  16
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: 36514
    
  16
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with scanner class execution
 
Similar Threads
Parsing text file into 3 columns
Scanner
To validate telnet connectivity in java code