• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it is always giving output as found null eventhough i am giving input at runtime...
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try a[0] as "\\d\\d"
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ankit

still same output:found null
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic