• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with scanner class execution

 
sandeep patrudu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ritchie,

Thanks for helping me on this
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic