| Author |
Scanner...K&B p.no:484
|
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
it is always giving output as found null eventhough i am giving input at runtime...
|
SCJP5 and SCWCD1.5
Think Twice Act Wise...
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
ganesh can you please tell what you are passing as parameter to the program i.e. the command line arguments and what are you providing input when prompted???
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
i am giving input as :34adkjg345kjh and a[0]="\d\d" [ November 11, 2008: Message edited by: Ganeshkumar cheekati ]
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
try a[0] as "\\d\\d"
|
 |
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
ankit still same output:found null
|
 |
Ken Truitt
Ranch Hand
Joined: Aug 23, 2007
Posts: 124
|
|
Then try just \d\d without quotes. On my system, it worked for \d\d and for "\d\d", but NOT for "\\d\\d", which returned only "found null." My code was slightly different: [code] import java.util.*; import java.io.*; public class TestScan { public static void main(String[] args) { String token = null; System.out.println("Input: "); System.out.flush(); try { Scanner sc = new Scanner(System.in); do { token = sc.findInLine(args[0]); System.out.println("Found: " + token); } while (token != null); System.in.close(); } catch(IOException io) { System.out.println(io.getMessage()); } } } [code] [ November 11, 2008: Message edited by: Ken Truitt ]
|
SCJP 88% | SCWCD 84%
|
 |
 |
|
|
subject: Scanner...K&B p.no:484
|
|
|