• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scanner...K&B p.no:484

 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

it is always giving output as found null eventhough i am giving input at runtime...
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am giving input as :34adkjg345kjh

and a[0]="\d\d"
[ November 11, 2008: Message edited by: Ganeshkumar cheekati ]
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try a[0] as "\\d\\d"
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ankit

still same output:found null
 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic