Sunday 15 January 2012

java - working code in Ubuntu terminal, doesn't work in Windows Eclipse -



java - working code in Ubuntu terminal, doesn't work in Windows Eclipse -

i'm trying parse day format "dd/mm/yyyy" usedelimiter faced unusual problem. used code below, works on ubuntu terminal.

scanner k = new scanner(system.in); k.usedelimiter("/|\n"); string day,month,year; day = k.next(); month = k.next(); year = next(); system.out.println(day + "/" + month + "/" + year); int d = integer.parseint(day); int m = integer.parseint(month); int y = integer.parseint(year);

but on windows when re-create code eclipse, gives error @ :

int y = integer.parseint(year);

i've found causes this. when print "year", prints 2014 there whitespace @ end of 2014 integer isn't parsed correctly. solved changing code in eclipse to:

year = next().trim();

but :

my question is, how can possible same code works on ubuntu not on windows platform ?

try adding \r delimiters. in ubuntu new line \n while in microsoft new line '\r\n'

java eclipse windows parsing ubuntu

No comments:

Post a Comment