Results 1 to 2 of 2
  1. #1
    potanta is offline Member
    Join Date
    Jan 2016
    Rep Power

    Default How to turn this program to have the user input the word and the letter? (BlueJ)

    I am having so much trouble with this program. I have to make this program for a grade and I am struggling so much with it. I have to make a program where the user has to type a word, then type a letter, then BlueJ has to remove any occurrence of that particular letter. And I have to use the Scanner class. If you look at the coding of a program which i posted down below, noticed that I copied this Java program online which has the right concept, but it does not allow a user to input it. If you copied and pasted the code, this example program would work, but I have to make the user input the word and the letter. And it's hard because you can't just import a "char". So what do I do? Help I am stuck? And how do you delete a Char? BlueJ won't even compile for that.

    By the way, my teacher gave us an algorithm to follow using a while loop. Here is the algorithm in English:

    int loc = x.indexOf(y)

    while there are more letters to remove
    take out the letter ( substring )
    loc = x.indexOf(y)

    Java Code:
    import static java.lang.System.*;
     * This basic java example source code
     * shows how to delete all occurrences of a character on a String
    public class DeleteAllOccurrencesCharacter {
    	public static void main(String[] args) {
    		// Declare a string object
    		String strValue = "aaxabbccddeefff";
    		// call a method to delete all occurrences
    		String newString = deleteAll(strValue, "a");
    		// print the new string value
    		out.println("New String:" + newString);
    	private static String deleteAll(String strValue, String charToRemove) {
    		return strValue.replaceAll(charToRemove, "");

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: How to turn this program to have the user input the word and the letter? (BlueJ)

    You can prompt for a String. If they give you more than a single character, just use the first character and ignore the rest. To delete a character where a String is expected, convert character to a String. The Character class should help with that. A quick way (but not internally efficient) is do do the following:
    Java Code:
    String charString = 'c' + "";
    And please don't continue to start new threads for the same topic. Just continue on with the previous threads you started. You will still get help.

    Last edited by jim829; 01-29-2016 at 11:24 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 1
    Last Post: 01-29-2016, 01:15 PM
  2. Replies: 3
    Last Post: 11-17-2012, 09:07 AM
  3. Program not waiting for user input
    By kkid in forum New To Java
    Replies: 2
    Last Post: 11-11-2012, 05:17 AM
  4. user input program
    By myalani in forum New To Java
    Replies: 4
    Last Post: 10-28-2011, 04:07 AM
  5. Replies: 13
    Last Post: 10-31-2010, 08:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts