This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Scanner...K&B p.no:484 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Scanner...K&B p.no:484" Watch "Scanner...K&B p.no:484" New topic
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
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

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
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

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%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scanner...K&B p.no:484