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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:07:30+00:00 2026-06-16T06:07:30+00:00

I am writing a program where if someone types in the following two lines:

  • 0

I am writing a program where if someone types in the following two lines:

HELLO, I’D LIKE TO ORDER A FZGH

KID’S MEAL

The program will output it like this:

HELLO, I’D LIKE TO ORDER A KID’S MEAL

In other words, the “FZGH” the user inputs into the sentence will be replaced with the second line’s words, as you can see: the “FZGH” is replaced by “KID’S MEAL.” Kinda get what I mean? If not, I can elaborate more but this is the best I can explain it as.

I’m really close to solving this! My current output is: HELLO, I’D LIKE TO ORDER A FZGH KID’S MEAL

My program didn’t replace the “FZGH” with “KID’S MEAL,” and I don’t know why that is. I thought that by using the .replaceAll() thingy, it would replace “FZGH” with the “KID’S MEAL,” but that didn’t really happen. Here is my program so far:

public static void main(String[] args) {
    sentences();
}

public static void sentences() {
    Scanner console = new Scanner(System.in);
    String sentence1 = console.nextLine();
    String sentence2 = console.nextLine();
    //System.out.println(sentence1 + "\n" + sentence2);
    String word = sentence1.replaceAll("[FZGH]", "");
    word = sentence2;
    System.out.print(sentence1 + word);

}

Where did I mess up, resulting in the FZGH still appearing in output?

  • 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-16T06:07:32+00:00Added an answer on June 16, 2026 at 6:07 am

    Use

    sentence1 = sentence1.replaceAll("FZGH", "");
    String word = sentence2;
    

    Your first (and primary) problem is that you’re creating a new String named word, that you’re setting to the value of sentence1.replaceAll("[FZGH]", ""). You’re then changing the value of word to be sentence2 immediately afterward, so the replacement is lost.

    Instead, setting sentence1 to sentence1.replaceAll("FZGH", ""); will change sentence1 to no longer contain the string "FZGH", which is what you’re going for. You don’t actually need a word value at all, so if you’d like to remove it, it wouldn’t hurt.

    In addition, using [FZGH] will replace all F‘s, Z‘s, G‘s, and H‘s from the string- you should use FZGH instead, as this will only remove instances of all four letters in a row.

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

Sidebar

Related Questions

I'm writing a custom structure manipulation program, and I've got the following types: type
I was writing a program to concatenate two arrays in C. I am allocating
I'm about to start writing a program which will attempt to extract data from
I'm writing this program that will need to access the registry to pull some
I am writing a program that will eventually be used to have one child
I'm writing MIPS program that will examine a list of 10 numbers to be
I'm writing a program that, using Rijndael, will encrypt and decrypt files/folders using a
Can someone help me on how to go about writing a program for (say
I am writing a program in Qt that looks like this: The main window
Perhaps someone can help me out here. I'm writing a program in C# to

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.