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 6732461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:39:14+00:00 2026-05-26T10:39:14+00:00

I have modified my code, I am making a decoder that decodes as follows:

  • 0

I have modified my code, I am making a decoder that decodes as follows:

“2” as “a”, “22” as “b”, “222” as “c”, “3” as “d” etc

I’ve written the following logic to implement it

    Scanner input = new Scanner(System.in);
    System.out.println("Please enter the string encoded with appropriate T9 encoding algorithm");
    String lStr=input.nextLine();
    String[] tokens=lStr.split("\\s|0");
    System.out.printf("Number of elements are: %d\n The text entered is: ", tokens.length);
    for(String token: tokens)
    {
        if(token.equals("2")){
            output=token.replace("2", "a");
        }
        else if(token.equals("22")){
            output=token.replace("22","b");
        }

       //etc

If I give it an input like 2022 222 it decodes it as “abc” which is right but I wanted it to print “a bc” whenever it encounters a 0 as if in 2022 222, how can I achieve that, ive used 0 as a token along with white space, how can I tell it to put a space after reading 0 in the string?
Help please!

  • 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-05-26T10:39:15+00:00Added an answer on May 26, 2026 at 10:39 am

    String lStr=input.nextLine(); is the problem. Try checking the value of lStr at runtime – it will be the value of the whole line (perhaps unsurprisingly given the name of the method).

    To continue with this approach, you’ll need to read the whole line in as you do, but then check each token (there’s a method to do this) for a match with your encoding scheme.

    E.g. If you read a line in:

    lStr = “2 22 222 2222”;

    which won’t match your scheme at all – you don’t have a value coded up as “2 22” do you?

    HTH.

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

Sidebar

Related Questions

I have the MySQL Connector/NET installed on my PC. I modified the source code
I have modified a working Windows service that had always been starting beforehand. After
I have a dataset that I have modified into an xml document and then
I'm interested in making an immutable class that has properties that cannot be modified,
I have code listed here: Threading and Sockets . The answer to that question
I have written a script using my local PHP 5.3 installation making use of
In the company I work for, we have the policy that all code should
I have a lot of code that performs bitwise operations on unsigned integers. I
I have modified the Nerd Dinner application to allow editing of child records by
I have modified my MOSS 2007 configuration to query a given target AD successfully.

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.