Help removing char from midpoint of string using deleteCharAt()

How do you properly remove a char from a String at its midpoint? My attempt is on Line 80 and it does not want to work.
I am using [http://java.sun.com/j2se/1.3/docs/api/java/lang/StringBuffer.html|http://java.sun.com/j2se/1.3/docs/api/java/lang/StringBuffer.html] as a reference for deleteCharAt()
Am I on the right track or should I try something else?
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Palindromes extends JFrame implements ActionListener
     JPanel centerPanel = new JPanel();
     JLabel enterDataLabel = new JLabel("  Enter a word or phrase with no punctuation: ");
     JTextField enterDataField = new JTextField(15);
     JLabel displayLabel = new JLabel("");
     JLabel spacer = new JLabel("");
     JButton submitButton = new JButton("Check");
     JButton clearButton = new JButton("Clear");
     public static void main(String[] args) throws IOException
          try
               UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
          catch(Exception e)
               JOptionPane.showMessageDialog(null,"The UIManager could not set the Look and Feel for this application.","Error",JOptionPane.INFORMATION_MESSAGE);
          Palindromes f = new Palindromes();
           f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         f.setSize(300,120);
           f.setTitle("Playing with Palindromes");
           f.setResizable(false);
           f.setVisible(true);
     public Palindromes()
          Container c = getContentPane();
          c.setLayout((new BorderLayout()));
        centerPanel.setLayout(new GridLayout(6,1));
               centerPanel.add(spacer);
               centerPanel.add(enterDataLabel);
               centerPanel.add(enterDataField);
               centerPanel.add(displayLabel);
               centerPanel.add(submitButton);
               centerPanel.add(clearButton);
               submitButton.addActionListener(this);
               clearButton.addActionListener(this);
               c.add(centerPanel, BorderLayout.CENTER);
               addWindowListener(
                     new WindowAdapter()
                         public void windowClosing(WindowEvent e)
                                int answer = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit?", "Palindromes", JOptionPane.YES_NO_OPTION);
                                 if (answer == JOptionPane.YES_OPTION)
                                      System.exit(0);
     public void actionPerformed(ActionEvent e)
           String arg = e.getActionCommand();
          if(arg == "Check")
               String word = enterDataField.getText();
               int wordSize = word.length();
              int midpoint = wordSize/2;
               deleteCharAt(midpoint);
               StringBuffer lastHalf = new StringBuffer(word.substring(midpoint));
               StringBuffer firstHalf = new StringBuffer(word.substring(0,midpoint));
               if (lastHalf == firstHalf)
                    displayLabel.setText(word + " is a palindrome!");
               else
                    displayLabel.setText(word + " is NOT a palindrome!");                    
          if (arg == "Clear")
               enterDataField.setText("");
               displayLabel.setText("");
}

Looce wrote:
80 |               deleteCharAt(midpoint);
82 |               StringBuffer lastHalf = new StringBuffer(word.substring(midpoint));
83 |               StringBuffer firstHalf = new StringBuffer(word.substring(0,midpoint));line numbering courtesy of GNOME's text editor(replying to self)
deleteCharAt is an instance method of StringBuffer, so you need to have one to work with. Suggestion: drop lines 82/83 and use String result = new StringBuffer(word).deleteCharAt(midpoint).toString();

Similar Messages

  • I need help removing CS3 from Windows 7 so I can reinstall

    I need help removing CS3 from Windows 7 so I can reinstall

    Before trying to remove try re-installing CS3 right on top of the current install.  Often re-installing Photoshop on top of itself fixes the install.  If it does be sure to apply the cs3 updates.
    Download Adobe CS4 and CS3 Free Trials Here (incl. After Effects) | ProDesignTools
    your product key can be retrieved from here https://www.adobe.com/account/my-products-services.html
    use these links for the updates.
    Adobe - Photoshop : For Macintosh
    Adobe - Photoshop : For Windows

  • TS1389 I need help removing UAC from itunes..

    I need help removing UAC from itunes so it will not allow me to open itunes. Everything I have read from other comments that you shouldn't turn off your user account control. I just to be able to open itunes. Can anyone help me with this problem?? Greg, ogrady612@yahoo,com

    I had this problem too but you do not need UAC to be turned on.
    Click on start and search for 'uac' in the search box at the bottom and click on 'Change User Account Control Settings' when it comes up. Move the slider to the bottom when the window appears and save the changes and your done!
    It's worked for me and my uac has been off for months without causing me any problems!
    Hope this helped

  • HT1222 How do I remove apps from staying alive after using them so as to reduce battery usage?

    How do I remove apps from staying alive after using them so as to reduce battery usage?

    double click the home button and swipe the app window up and off of the screen

  • Any help removing ICSPA from Firefox on my MacBook Air?

    any help removing ICSPA from Firefox on my MacBook Air?

    Good you found the answer. It was really a question for the MacBook Air forum.

  • My daughter wants to remove herself from our plan and use a different cell provider. However, our contract is not yet up, what is the penalty for removing her early?

    My daughter wants to remove herself from our plan and use a different cell provider. However, our contract is not yet up, what is the penalty for removing her early?

    For contacts started before November 14, 2014, the ETF is $350 minus $10 per month of the contract term completed for smartphones. For other ddv6,it is $175 minus $5 per month of the contract term completed. You will need to call customer service at 1-800-922-0204 or *611 to find out the ETF amount for contracts started on and after November 14, 2014.

  • Need help REMOVING ALARM FROM ipod.

    I use my 3G ipod in my car with an alpine stereo that supports ipods. Every now and then the alarm sets its self and will go off in the middle of the night completely draining my battery by the next morning.
    Is there any way I could remove or delete the alarm function from my ipods software?

    When you say you want to "remove" pictures from the iPod, do you mean you want to transfer those pictures from your iPod to your new computer? If so, do not erase and sync your iPod as you will lose all those pictures from your iPod for ever.
    If you copied photos to your iPod using the full resolution option, enable disk use, open your iPod in "my computer", open the photos folder then open the "full resolution" folder and drag the photos out of that folder to your desktop. For enabling disk use look here.
    Disk Use.
    If you only copied the photos as thumbnails, you can't do this so you'll need a program such as this one.
    iPod Photo Copy. (Windows only)
    iPod Photo Liberator. (both Mac and Windows versions available)
    Photos as thumbnails won't be of the original quality when copied back to your computer.
    And btw, this is a "connecting iPod classic to a Mac" forum!

  • HELP REMOVE FOXFIRE FROM MY COMPUTER, PLEASE...

    I WAS CLICKING DOWN THE E-MAIL LIST TO DELEAT E-MAILS THAT WERE OBVIOUS SPAM, WHEN DELEATING AN EMAIL OFFERING CAR DEALS, MY VIRUS PROGRAM POPPED UP A FULL PAGE WARNING,"THIS PROGRAM HAS CONTRACTED A TROJON, SHUT YOUR COMPUTER DOWN IMMEADIATELY" SO I DID. I RESTARTED IT AND RAN A FULL SCAN, TWO ITEMS WERE FOUND AND GAVE ME THE OPTION TO QUARENTEEN THEM OR DELEAT THEM I DELEATED THEM, THAN RAN A QUICK SCAN, THEY WERE STILL THERE. SO I CALLED MICROSOFT, TURNED OVER CONTROLL AND WATCHED THE TECH. WORK AND SCAN FOR MOST OF THE NITE. FINISHING ALL THE WORK THEN RAN AN EXTENSIVE SCAN LOCATE AND DESTROY PROGRAM THAT RAN ANOTHER 5 OR 6 HRS. AROUND 2AM IT FINISHED. I RESTARTED IT, CHECKED IT OUT AND SHUT IT DOWN AND WENT TO BED. NEXT DAY ,ALL DAY FOXFIRE HAD ONE FAILURE AFTER ANOTHER UNTILL I WAS NOT ONLY FRUSTRATED, EVERYONE I CALLED FROM THE PROVIDER TO MY SERVICE PROVIDER AND ALL SAID JUST TO REMOVE IT SINCE MICROSOFT GOT MY MINE FIXED ITS ONLY FOXFIRE THAT GOT INFECTED, I SHUT IT DOWN BEFORE IT MADE THE JUMP FROM FOXFIRE TO MY COMPUTER, BUT FOXFIRE WILL NOT ALLOW ME TO REMOVE IT FROM MY PROGRAM REMOVAL SITE. HELP I WANT IT GONE COMPLEATELY. HELP.

    For details of how to remove add-ons see https://support.mozilla.com/kb/Uninstalling+add-ons

  • Removing segment from the concatenated String...

    Hi,
    please any one tell me that what will be the query to separate segments from the concatenated string.
    For instance, if the segment value passed is
    ‘000-000-abcd-10001-post-000-21000’, then the following output should get displayed.
    000
    000
    abcd
    10001
    post
    000
    21000
    Thanks in advanced

    test it:
    with
      test_table as
          select '000-000-abcd-10001-post-000-21000' as str from dual union all
          select '111-222-cdef-20002-test' as str from dual
    select v.str,
           substr( my_str,
                   instr(my_str,'-',1, rn) + 1,
                   instr(my_str,'-',1, rn + 1) -  instr(my_str,'-',1, rn) - 1
                 ) as new_str
      from (
             select '-'||ltrim(rtrim(str,'-'),'-')||'-' as my_str,
                    str
                 from test_table
           ) v,
             select level as rn
                 from dual,
                        select max(length(str) - length(replace(str,'-'))) max_len from test_table
              connect by level <= max_len + 1
            ) pivot
    where (length(str) - length(replace(str,'-'))) + 1 >= rn
    order by str, rn
    Query finished, retrieving results...
                   STR                   NEW_STR
    000-000-abcd-10001-post-000-21000    000
    000-000-abcd-10001-post-000-21000    000
    000-000-abcd-10001-post-000-21000    abcd
    000-000-abcd-10001-post-000-21000    10001
    000-000-abcd-10001-post-000-21000    post
    000-000-abcd-10001-post-000-21000    000
    000-000-abcd-10001-post-000-21000    21000
    111-222-cdef-20002-test              111
    111-222-cdef-20002-test              222
    111-222-cdef-20002-test              cdef
    111-222-cdef-20002-test              20002
    111-222-cdef-20002-test              test
    12 row(s) retrieved

  • Help removing imessage from a phone number no longer being used by an iphone

    Hi everyone. Hoping for some help with a bizarre issue. I switched from an iphone 3gs to an android a few months ago, but when some (not all) friends w/ iphone's text me, it tries to send it as an imessage from their phones. I  don't receive the texts for hours at a time. Is there something I can do to prevent this? Or is on their end? This has even happened with people who I have exchanged numbers with well after I made the switch from iphone to android which I find particularly weird.

    If you still have your 3GS put your SIM back in it and turn off iMessage.  If you don't have it but you did register it with Apple, do this:
    Go to: https://supportprofile.apple.com/MySupportProfile.do
    Log in if not already logged in
    Click on "edit products"
    Click on the "x" to the right of the product
    Click "unregister"
    This deactivates number with iMessage.

  • Fm to Remove chars from tel num

    Is there a function module that will delete all special characters and non numeric characters from a telephone number?

    Hi ,
    This can be easily achieved using a logic.
    compare the given data with the string '0123456789'  and ifin comparison you find anything apart from this delete this value.
    Sample logic
    m_valid = '0123456789'
      m_strlen = STRLEN( phone_number ).
      DO m_strlen TIMES.
        m_char = phone_number+m_pos(1).
        IF m_valid NS m_char.
          phone_number+m_pos(1) = ' '.
        ENDIF.
        m_pos = m_pos + 1.
      ENDDO.
    after this condense ur string to remove the spaces.
    Regards,
    Anuij

  • Need help removing adware from Safari Version 7.0.5 (9537.77.4) Maverick System OS X 10.9.4 (13E28)

    This adware renders system useless during while using web. Cannot perform even the simplest work that requires interaction on a website. (Except Apple). I have excellent Web Service. Other iMac and 4 IOS devices are not affected, and work well. 

    Hello Apple community
    PLEASE I need your help!
    I'm having an horrible experience with my Safari 7.1.2 ( iMac OS X 10.9.5)
    Bare with me, here are my symptoms, and what I did so far looking for solutions online. None of them helped
    This all started SUDDENLY, today. Although i DOWNLOADED a couple of apps last week  thinking i was upgrading my video app that wasn't working (I was prompted to do so but the video never ended up working!)
    My symptoms:
    - Ads are "glueing" themselves on my webpages... in different formats depending on the website i'm on (regular websites...)
    - pages are opening ups by themselves (see picture) :
    *directing to "d2bzz.resolve.sweepstakesghost.biz/?sov....." with a window saying "PC TECH SUPPORT Chat initiated. Specialist: Matt Folson Date: January 7, 2015";
    To this i turned my Wifi off and then closed the page to avoid clicking on the OK button (yet now it's not asking anymore and just redirecting me without asking)
    *directing to other supposedly technical support...
    - SELECTED WORDS become all caps, underlined, and in light blue with a link to an ad? (see picture above)
    - ALL of this are displaying a certain "Ad by PJS-4.2"
    My Solutions:
    1)
    I searched online and DOWNLOADED
    -Clamsav: found items to remove and removed them and emptied my trash ---> Dindt work (see picture)
    - ADWARE Medic: found a couple of other items to delete and deleted them , emptied trash and restated computer ----> didn't work!
    Still same Symptoms!
    2)
    I checked my extensions for Safari and only found 3 that I do use (and been using for quite a while). Just uninstalled them
    Still same symptoms!
    3)
    I also looked for your files “Linc Davis” is referring to here in the forum but can't find any of them in my COMPUTER.
    Triple-click anywhere in the line below on this page to select it:
    /Library/LaunchAgents/com.vsearch.agent.plist
    Right-click or control-click the line and select
              Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item named "VSearch" selected. Drag the selected item to the Trash. You may be prompted for your administrator LOGIN password.
    Repeat with each of these lines:
    /Library/LaunchDaemons/com.vsearch.daemon.plist
    /Library/LaunchDaemons/com.vsearch.helper.plist
    /Library/LaunchDaemons/Jack.plist
    Restart the computer and empty the Trash. Then DELETE the following items in the same way:
    /Library/Application Support/VSearch
    /Library/PrivilegedHelperTools/Jack
    /System/Library/Frameworks/VSearch.framework
    ~/Library/Internet Plug-Ins/ConduitNPAPIPlugin.plugin
    4)
    I did an other search recommended by “Linc Davis”, about looking for     /Library/LaunchDaemons        in the Finder and I FOUND this:
    com.smithmicro.schedulerdaemon.plist
    com.MICROSOFT.office.licensing.helper.plist
    com.surteesstudios.hddfancontroldaemon.plist
    com.adobe.fpsaud.plist
    com.macpaw.CleanMyMac2.Agent.plist
    com.apple.aelwriter.plist
    com.adobe.SwitchBoard.plist
    com.apple.qmaster.qmasterd.plist
    com.adobe.versioncueCS3.plist
    com.bombich.ccc.plist
    PLEASE PLEASE HELP what can I do to GET RID OF those?!!

  • Help Removing Messenger from Windows 7

    How do I remove Windows Live Messenger from my computer?  Every time I log into hotmail it open the messenger and tries to get me to log in.  I don't want to use the messenger.....ever!  Please help!!!!
    Thanks
    Solved!
    Go to Solution.

    If its asking you to pay to get it taken off, then you are infected with spyware, garbageware etc. This might be a job for Geek Squad since I dont want to direct you to remove anything that might further cripple your machine (A program called Hi-Jack this can help with the removal of it, but Im not by any means an expert at reading those logs.
    *******DISCLAIMER********
    I am not an employee of BBY in any shape or form. All information presented in my replies or postings is my own opinion. It is up to you , the end user to determine the ultimate validity of any information presented on these forums.

  • Need help removing PDF from "Places" in Finder window

    I just noticed this PDF in my sidebar and I can't remove it, "Catalyst Itenerary 2012"
    It's an old document I must have dropped it in here at some point but must no longer exist on my computer because Spotlight cannot find it.
    I'm able to select everything in the sidebar except this PDF. I can't select it or highlight with my pointer, I can't right-click it to choose the "Remove from sidebar" option.
    Please help, I'm stumped.

    If you're on Snow Leopard, then hold the Command key down as you drag it off.
    For Leopard like your profile shows, it should just drag off.

  • I need help removing bezel from my laptop screen

    I have a HP Pavilion DV4-1125nr laptop and I cracked the screen and need to change it but I can't seem to figure out on how to remove the bezel out of my screen so I can remove screen and get the model number from the back.  I removed screens before but they had screws on top of bezel covered by little rubber knobs and the dv4-1125nr doesn't have any of this and it looks like you have to remove the bezel using your hands but I can only pop out the top and the sides, the bottom doesn't pop out and I'm afraid to force it out in case I break it.  What am I misssing here?  Is there a trick to get it out?

    http://h20574.www2.hp.com/?jumpid=reg_R1002_USEN&lang=en&cc=US&hpappid=psml
    From above url ( HP partner Services Media Library ), do the following;
    1. Select Laptops and Teblet PCs in "Product Category"
    2. Select HP Pavilion Notebook PCs in "Product Family"
    3. Select Pavilion dv4-1000 Entertainment Notebook PC series in "Product Series"
    4. Select either FRU Remove/Replace (AMD) or FRU Remove/Replace (Intel) based on your CPU type.
    5. It should bring up another window "HP Service Media Library" and then select Display Bezel ( Recessed ) to bring up the video and detailed procedure for you to open up the LCD Display Bezel.
    Have fun and keep this URL handy and you can use it for all your DIY works later.

Maybe you are looking for

  • How can I read a pdf file using an ALC process

    I have a pdf form with a schema, I want to read the pdf form in to an xml with same schema so that i can process the data  that i get from the pdf file. I have tried the following      I have created an input document variable (where i ll give my pdf

  • Choose random image script

    I'm creating a small movie with a set of random images that all appear in the same spot (no horizontal or vertical movement). I want each image to appear onscreen for two seconds, then be replaced by another randomly-chosen image. There are 17 images

  • Cannot start Classic mode after 10.3.9 update

    Hi! I recently used the "Software Update" tool to update my 10.3 OS version to 10.3.9. After doing this, I found that I could no longer start Classic mode while in OSX. I did a clean install and can boot using OS 9.2.2, no problems. But I still canno

  • Server 2012 R2 - Dedup chunk store bigger than original data

    Hi there, I have a fresh install of a Windows Server 2012 R2 as fileserver with deduplication enabled on several volumes. One volume shows a strange behavior after a couple of weeks in productive environment: Initially I had a dedup saving rate of ~1

  • Doubt about MI Client

    Hi, Does MI Client supports a login online? When the user entries in MI, the MI Server recept a notification that the user do the login in the MI? I registried a user, sync, MI Client gets a DEVICE ID XXX and the app is installed in MI.  Now i want r