Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:00:26+00:00 2026-06-18T10:00:26+00:00

I am new to Java and learning it. I have written a code to

  • 0

I am new to Java and learning it. I have written a code to take user input and tokenize it. It compiles successfully but when run produces ‘-3’ as o/p.

import java.io.*;


public class TokenTester{

    public static void main(String[] arguments){
    String name;
    StreamTokenizer token;
    BufferedReader reader;
    reader = new BufferedReader(new InputStreamReader(System.in));

     try{
            System.out.println("Enter a String  ");
            name = reader.readLine();
            System.out.println(name);
            token=new StreamTokenizer((new StringReader(name)));
           //token=new StreamTokenizer(name);
            // Using new StreamTokenizer(name) throws error
            //error: no suitable constructor found for StreamTokenizer(String)
             while(token.nextToken()!= token.TT_EOF)
            {
             System.out.println(token.nextToken());
                }
            }
        catch (IOException ioe){
             System.out.println("An unexpected error occured.");
        }

        }
    }

Also when I use new StreamTokenizer(name) throws error
“error: no suitable constructor found for StreamTokenizer(String)”

When I use while(token.nextToken()!= token.TT_EOF)
it shows infinite loop is -1 as o/p

Below code works absolutely fine:

import java.util.StringTokenizer;

 class TokenTester {

 public static void main(String[] arguments) {
 StringTokenizer st1, st2;

 String quote1 = "VIZY 3 -1/16";
 st1 = new StringTokenizer(quote1);
 System.out.println("Token 1: " + st1.nextToken());
 System.out.println("Token 2: " + st1.nextToken());
 System.out.println("Token 3: " + st1.nextToken());

 String quote2 = "NPLI@9 27/32@3/32";
 st2 = new StringTokenizer(quote2, "@");
 System.out.println("\nToken 1: " + st2.nextToken());
System.out.println("Token 2: " + st2.nextToken());
System.out.println("Token 3: " + st2.nextToken());
 }
 }

I am not able to figure out the issue in my code.
Please guide.

I have refered:

http://tutorials.jenkov.com/java-io/streamtokenizer.html
http://www.java-samples.com/showtutorial.php?tutorialid=397
http://docs.oracle.com/javase/7/docs/api/

Thanks
Gaurav

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:00:29+00:00Added an answer on June 18, 2026 at 10:00 am

    In first example you use StreamTokenizer and in the second – StringTokenizer. So, in first example, to make it workable you should replace StreamTokenizer by StringTokenizer. And of course you should then use appropriate methods which are relevant to StringTokenizer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to learning JSPs and Servlets. I have a Java class which calls
I am new to java servlets. I learning from the basic. I have a
I am new to Java, started learning swing and have a problem with resizing
I have been learning Java for a while now and still learning new syntax
I am new to Java (but have a fair bit of .NET experience). I
I'm learning java and have a bit of code I am trying to write
just learning Java and I know this may sound stupid but I have to
I have just started learning java, and know only a small amount of code,
I am new to java(learning JSF and other JAVA EE components) and have a
I have just started learning java. I modified the client side code for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.