This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread 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


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: 9303
    
  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: 9303
    
  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%
 
GeeCON Prague 2014
 
subject: Scanner...K&B p.no:484