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

  • SEARCH
  • Home
  • 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 8892371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:58:53+00:00 2026-06-14T22:58:53+00:00

I have here two problems needed to be solved. First off: I have here

  • 0

I have here two problems needed to be solved. First off: I have here my program, wherein I want that whatever the user inputs will be saved on a string, and to be placed in an array.

my codes:

String words;
    String replaced_words;

    Scanner s = new Scanner (System.in);

        System.out.println("Enter a line of words basing on an event, verse, place or a name of a person.");
        words = s.nextLine();
        System.out.println("Word accepted!");
        //using char array method
        char [] c = words.toCharArray();

Now, I used the replace method for the string such as this:

String replace = words.replace(' ', '-');

But the problem is, this occurs as an error. By replacing the ‘ ‘ character into words such as:

String replace = words.replace(words, '-')

although I want to limit the length of the hyphens depending on the numbers of characters on the words.

The output of this program should be the following:
· Create a copy of this string to an array where each letter is replaced with a hyphen (-) and each space is replaced with an underscore (_). Symbols and numbers will remain shown.

The problems I’m getting is that it doesn’t replace them with a hyphen and underscore. It just displays the inputted text I did just typed via scanner.

  • 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-14T22:58:55+00:00Added an answer on June 14, 2026 at 10:58 pm

    To achieve your goal you can use:

        String word = "AB CD EF";
        String replace = word.replace(' ' , '-').replaceAll("[^\\-]", "_");
        System.out.println(replace); // prints "__-__-__"
    

    if you want spaces between the underscores (to distinguish them from each other) you can use

        for (int i = 0; i < replace.length(); i++) {
            System.out.print(replace.charAt(i) + " ");
        }
        // prints "_ _ - _ _ - _ _ "
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem: I have two columns in a table that, for each
I have a menu bar that is rotated slightly. Here are two buttons as
I have a bit of an architecture problem here. Say I have two tables,
I have two questions here. How can I show the header of the pop
I have two functions here function Preloader() {} Preloader.prototype = { init:function() { //
I have read here http://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/ about how you probably shouldn't be trying to un-flatten
I have a question, here are two classes below: class Base{ public: virtual void
I have a very strange behavior with Request.Form . Here are two IIS 7
What is the issue with this code? Here we have two files: classA.h and
I have two tables as shown here . I am trying to fetch name

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.