Changing one character in a string...how hard can it be...???

Hey guys,
I posted something the other day about changing a binary string to one complement. Well, now I want to change that again to the two's complement of the same number.
The (messy) code I got so far is as follows:
import java.util.*;
class twosComplement {
  public static void main(String[] args) {
      Scanner reader = new Scanner(System.in);
      String binary;
      String i = "0";
      String j = "1";
      System.out.println("Enter a binary String:");
      binary = reader.nextLine();
   //   int x = 15;
   // String binary = Integer.toBinaryString(x);
   // binary = ("00000000"+binary).substring(8-binary.length());
    System.out.println("Your binary number is " +binary);
    String complement = binary.replaceAll("0","x").replaceAll("1","0").replaceAll("x","1");
    System.out.println("One's complement of your binary number is " +complement);
    int n = 0;
    int k = binary.length()-n;
    String m = charAt(k);
    if (charAt(k).equals(i)) binary.replace(charAt(k), j);
    else n++;
    System.out.println(binary);
//    do {k++; }
//    while (charAt(k).equals(i)) 
    private static String charAt(int k) {
        throw new UnsupportedOperationException("Not yet implemented");
    }the bit at the bottom is something netbeans kindly offered to create for me, it cut out a few syntax errors but didn't quite get the program to work.
I'm pretty sure the root of my troubles is coming from the use of the "charAt" method, which as far as i know, would be better used with arrays, but I don't know of another way to sort this stuff...
any help would be muchly appreciated.
Aaron.

ok. The following is a section from the original code (see above). I was hoping this code would take a binary string (ie, '1010101') and change the least significant bit which is a '0' to a '1'. The following section is my attempt at solving this problem, but as I run it, I encounter errors. I've been studying java for 2 months. I would like to know if anybody knows WHY this isn't working, and could offer an alternative method (as I've already stated, I think the use of the method 'charAt' is the main problem)
int n = 0;
    int k = binary.length()-n;
    String m = charAt(k);
    if (charAt(k).equals(i)) binary.replace(charAt(k), j);
    else n++;
    }Is that better?

Similar Messages

  • TS1702 Why we still dont have sound notifications on iPhone??? This started in September with the launch of the new IOS and iPhone 5... I've been waiting and waiting and still nothing... How hard can this be to fix????????

    Why we still dont have sound notifications on iPhone??? This started in September with the launch of the new IOS and iPhone 5... I've been waiting and waiting and still nothing... How hard can this be to fix????????

    Hi guys... The notifications i'm speaking about are everything that happens on our facebook. The only exception where i get notifications is if someone actually use my name on a post, then i have a notification. Now, if it is a post on my wall, a comment on one of my photos or even a like, there is no sound or vibration at all.
    Also, when i say "We" is bacause  there are a few users complaining about the same. There are some other forums, specially on facebook about this. What happens is that facebook blocks some of those groups.
    One more thing is i did try all possible things to make sure i was doing the right things in order to have notifications. Slider is obviously not in mute position, notifications sounds are on on facebook settings on main settings and also inside the app they are on. Did try to switch everything off and reboot then change again. Did restore the iPhone as new a couple of times. And like i said, if someone actually write my name i will have sound notification...
    Anyway, many thanks for your help

  • Request old number back, how hard can that be!!

    I placed an order online for both infinity 2 and Telephone on the 23rd of September, however other than an order reference sent on email there was no further contact from BT, so I decided to call and find out when I was likely to have my service transferred from my previous ISP to BT only to be told my order was pending within the system and a new order had to be placed.
    I then placed the order with a sales representative that was only concerned about making the sale and gave me inaccurate information in relation to requesting my old number back from my previous ISP, as I was informed I could only make the request for my old number once my telephone and normal broadband was switched to BT.
    I was given a date for the transfer of my service on the 7th of october, whereby we didn't then have and telephone or broadband facilities from 0:00am on the 6th of October till 20:00pm on the 8th, therefore the very next day I requested my old number back and attempted to order BT infinity 2 online.
    apparently BT systems don't allow two orders to be placed at the same time so both orders somehow got cancelled, therefore I called customer services to order infinity 2 once again only to be told 4 days later that this order had also been cancelled.
    Someone then called with an Indian accent that I had a job understanding (does BT vet these call centres to ensure the staff that work there are intelligible ? ) stating that both by telephone and infinity orders had again been cancelled and I had to choose/prioritise what I wanted to be done first; such as infinity or my old number back, I naturally asked to have my old number back as my wife runs a beauty salon business from home that she has already lost custom; due to two new numbers already being issued to us.
    A new order was placed to request my old number back on the 16th of October to which I was told I had to wait eleven days for this to complete and then I could order infinity.
    I decided to call again this morning (23rd october) to request an update only to be told again by someone with an Indian accent (constantly asking him to repeat what he had said!! ) that they could not find my order again and informed me that they he had placed the order once again to which I have to wait five days, whereby he would call me back to pursue with my infinity order..
    How hard can it be to transfer my services to BT, my previous ISP completed the transfer on the date I was given, yet I'm still waiting for BT to have my number transferred from BT wholesale unbelievable!!
    I've even looked at my online bill and most of the charges I have incurred are from trying to sort out this mess by calling customers services in Falkirk that I am reluctant to pay as both my infinity and telephone orders are cancelled not from my doing but an ordering system that has numerous flaws built within in it, I'm annoyed with the whole process and wish I had stayed with my previous ISP, so can someone help me escalate this or guide me in the right direction to sort this issue out by somehow getting my old number back?? (30 day limit before my number is issued to someone else)   
    Solved!
    Go to Solution.

    After finally speaking with someone that first of all I could understand from Falkirk (not somewhere in Asia) and knew what they were doing, a test was done by placing a request for my number there an then to see what error message would display, then an only then did the representative know what type of request/form needed to be made.
    After seven days a mobile text was received stating that I had finally retrieved my old number back, although what I would advise everyone when switching to BT from a previous ISP and placing an order over the phone; make sure the request to transfer your old number is part of that initial order and don't let the sales department give you any inaccurate jargon/information to finalise that sale, customer services are apparently the only ones that can request your old number back as part of that order.
    Even though I have finally retrieved my old number back I am still now waiting for that number to be assigned to my broadband line as I still cannot upgrade to infinity with my broadband currently assigned to the number I was initially given when I switched to BT, therefore the system wont allow me to upgrade until the system recognises my details.
    Good Luck to anyone that encounters the same problems that I have, as its now been 5 weeks since my first order for BT for infinity, hopefully I will be able to place an order sometime today when both my telephone line and broadband are synced to the same telephone number.

  • How to change one character string to char

    hi all
    i got string but only one character
    i got 1,2,3,E
    since i got 'E' here..........
    i need to convert to it to character....
    but how to change it.... i only know String to integer using Integer.parseInt() method....
    but i don't know about char...................

    You should really check the API first:
    http://java.sun.com/j2se/1.4.2/docs/api/index.html
    Take a look at String.charAt(int index) method.
    /Kaj

  • Update one character in a string

    Hello Experts,
    I would like to update a character in a string in a column using update statment.
    For eg in table a1 column has "ABCDEF", I would like change "C" with "c" . After change the a1 value should be "ABcDEF".
    Any help will be highly appreciated.
    Regards,
    Rashida

    Use Translate Function
    Example
    SQL> select translate('ABCDEF','C','c') from dual ;
    TRANSL
    ABcDEF
    Or Replace Function
    Exmaple
    SQL> select replace('ABCDEF','C','c') from dual ;
    REPLAC
    ABcDEF
    for table with column a1
    update a1 set col1 =  replace(col1,'C','c') ;
    OR
    update a1 set col1 =  translate(col1,'C','c') ;

  • Bluetooth on T500 and Win7-64bits... How hard can it be??!!

    Hello,
    I've read several posts about this, but none of them solved my problem.
    I have a T500 2055-RH2, with windows 7 64bits.
    I just bought a bluetooth mouse online and imagine how I feel after 3 hours of useless debugging to install a mouse. Actually, my problem is more basic, I just can't seem to have bluetooth working.
    I tried to install: Bluetooth with Enhanced Data Rate Software II for Windows 7, Vista - ThinkPad
    When I do install this, it eventually says I have no bluetooth device, so somehow my bluetooth adapter is NOT enabled. I then tried to do Fn-F5 to enable it, but it's no use, because I can only see my WIFI in there, no trace of bluetooth...
    From the forum, I tried to install: ThinkPad Power Management driver for Windows 7
    I think it was already installed, but I installed it anyway, still no change, nothing in Fn-F5, still nothing.
    I then even installed a WIDCOMM (broadcom) driver, but then again, it says it can't find any bluetooth device.
    Are there any depencies I don't know about? Should I reinstall anything? What the HELL is wrong?! How hard is it supposed to be to install such a basic function as bluetooth??!
    Should I throw that laptop out the window? Because I really want to... (arg!)
    Help please...!
    Thanks...
    Solved!
    Go to Solution.

    atreid, welcome to the forum,
    not wanting to be the "boo-man", are you sure your T500 has Bluetooth? It's not showing as having it on the support site when I look up your system.
    Product: ThinkPad T500 2055-RH2
    Original description: Based on 2055-CTO: T9400(2.53GHz), 4GB RAM, 320GB 7200rpm HD, 15.4in 1680x1050, 256MB ATI Radeon HD3650, CDRW/DVDRW, Intel 802.11agn, WWAN upgradeable, Modem, 1Gb Ethernet, UltraNav, Secure chip, Camera, 6c Li-Ion, WinVista Home Basic 32
    If I select another system, e.g. 20552BG, Bluetooth is listed as a component. T500 Display Parts List - Bluetooth daughter card.
    Maybe you could check if the hardware should be installed? You need to enter your type and s/n on this site and see if it mentions anything about Bluetooth, let us know what you find out.
    A just in case: -  Please do not post you s/n on these boards.
    Andy  ______________________________________
    Please remember to come back and mark the post that you feel solved your question as the solution, it earns the member + points
    Did you find a post helpfull? You can thank the member by clicking on the star to the left awarding them Kudos Please add your type, model number and OS to your signature, it helps to help you. Forum Search Option T430 2347-G7U W8 x64, Yoga 10 HD+, Tablet 1838-2BG, T61p 6460-67G W7 x64, T43p 2668-G2G XP, T23 2647-9LG XP, plus a few more. FYI Unsolicited Personal Messages will be ignored.
      Deutsche Community     Comunidad en Español    English Community Русскоязычное Сообщество
    PepperonI blog 

  • How hard can MySQL be?

    I am rebuilding a website for a band to make it more graphically pleasing. My concern is that the current site has a bulletin board/forum that is part of the hostprovider's package. I'm worried that I'm too inexperienced with mysql, php and/or everything else I will need to make the board work on my own osx server. So... just how hard could it be? How many steps and how many hoops will I need to jump through?
    Here is the forum in question:
    http://www.stereofuse.com/forum/
    I found the MySQL Manager and launched it... then promptly laughed at it's lack of any kind of hint whatsoever as to how it works or how to apply it in any way.
    I am a beginner so feel free to talk down.... way down.
    THANKS!
    Keith

    1) Introduce yourself to your new best friends over at http://www.phpbb.com/
    2) Install this on your server http://www.phpmyadmin.net/home_page/index.php
    3) Find out if the existing host will do a dump of the forum database or what tools they might offer for you to do the same. You'll need to know the database name, user name and password.
    4) Copy the template that's being used because it's not going to be in the fresh install of phpbb.
    5) Do a trial run while leaving the board up with a notice that it's going to be offline for a few days.
    6) Once you've figured out the steps take the board offline, export the database and make the real move. Leave the old board there until the new one is up.
    I'd expect you'll find good help in the phpbb forum. They really will be your new best friends ; )

  • HT2688 I have an Apple Id for my Itunes, and my children have a different Apple ID for theirs.  To home share, do I need to change one of the IDs for ITunes, or can we simply have a common Apple ID just for home sharing?  Thanks.

    I think the title says it all.  We have different Apple IDs on two computers for two users.  To home share, is it necessary to change one of the Apple IDs to match the other, or can this be done just for purposes of home sharing -- i.e., select one Apple ID as the common ID just for purposes of home sharing.
    Thanks,
    Eric

    Personally, I'd keep it simple and keep the same one.

  • Changing 1 character in a string

    following on from my last question...
    is there an easy way to set the value of one particular character at a certain index in a string? i'm suprised there's no setChar(index, char) kind of method in String.

    You could always roll-your-own, although this doesn't really change the string, it creates a new string (this e.g. is 1-based, adj if you want 0-based)
    class testing
      public static void main(String args[])
        String str = "Hello World";
        str = setChar(str,1,'W');
        System.out.println(str);
        System.exit(0);
      private static String setChar(String originalString, int position, char newChar)
        String newString = originalString.substring(0,position-1) + newChar +
                           originalString.substring(position);
        return newString;
    }

  • Find one character in a string and count the amount of times its found

    Hey SQL Forum experts.
    I have a string that is about 3000 characters long.
    I'm trying to search my string for the value '{'.
    Then I want to count how many times this value is found.
    How do I form the Oracle SQL to do this?

    Hi Colin,
    Try the following:
    SQL> var s varchar2(100)
    SQL>
    SQL> exec :s := 'Colin {{ Mackenzie {{{'
    PL/SQL procedure successfully completed.
    SQL> select length(:s) - length(replace(:s, '{')) Matches from dual;
       MATCHES
             5
    SQL> exec :s := 'I have a string that is about 3000 characters long'
    PL/SQL procedure successfully completed.
    SQL> select length(:s) - length(replace(:s, '{')) Matches from dual;
       MATCHES
             0Regards.

  • How hard can it be to uninstall Logic Pro 9??

    How do I uninstall Logic pro and all the programs that follow with it? I can´t find the answer anywhere. The answers I find are all older than 2010 and just includes deleting alot of strange files I cant find.
    And apparently theres no uninstall function either... frustrating.

    It's not hard, just drag the Logic app icon to trash, empty the trash, and that's it.
    You may also want to move Mainstage, Compressor, Waveburner, Logic Node, Soundtrack Pro and Apple Qmaster (depending on whether you had these installed along with Logic as a Logic Studio suite) to trash too.
    After that you may search the hard-drive for any Logic-related items, and trash them too. Check <your HD>/Library/Application Support/Logic AND <your HD>/users/<your username>/Library/Application Support/Logic (this one should contain your preferences, apple loops, custom sound patches, temp files and undo data).
    Apple Loops, Jam Packs and other Logic content (if you installed them all) could be found in: <your HD>/Library/Audio/Apple Loops/Apple/

  • I have a doubt that my iPhone is a used one . Any tips on how i can check ?

    I plugged my newly purchased iphone 4s into my laptop to sync with i-tunes and it showed " Babajee's iPhone " , which i not me .
    Am hoping that its not a used one . When i bought the phone the shopkeeper entered his Apple Id to setup my phone .
    But for the login you need an email id and password . His email id was "ManishYadav" , then how did " Babajee's iPhone " appeared when i connected the phone with itunes . It should've been " ManishYadav " since the shopkeeper entered his Apple id .
    Am so confused .
    Can someone please advise .
    Thanks .

    Nothing to hide bro . Yes i bought it from a local re-seller and not from the store . They sell it for a lower price .
    Does it ask for the name on the first boot ? I saw a couple of iphone "first boot / startup" videos on youtube and during the startup it asked for the Apple id , but nowhere did it ask for the iPhone name .
    I heard the first boot screen only comes once when you start the phone for the first time . So if it was used then the first boot screen wouldnt have appeared ?
    Isnt it ?

  • How hard can i push my MacBook Pro Retina?

    So I like to game on my macbook, but at the same time I'm afraid it won't last very long if I continue with it. If I have best resolution, maximum framerate (fps) etc will this hurt my mac or slow it down?
    I'm rocking a mid 2014 macbook pro retina 13 inc, with intel core i5, 2.6 ghz and 8 gigs of ram. Latest version of osx (yosemite). And I have intel iris 1536MB graphics card.
    So if I push my Mac too hard will it "survive" or whatever? I thought these computers were meant for this stuff, but I don't know, that's why i'm asking.
    Will battery life also drain after a while?
    I have tried best graphics and it handles it very well, but I have no idea if it's a smart thing to do. Will it destroy my mac?
    Any help would be much appreciated!
    Thanks,
    Magnus

    Macs are specifically designed for maximum performance, and are impossible to damage through normal use as long as you observe its published environmental specifications. That includes gaming or whatever else you need it to do. If it should reach a thermal limit that cannot be altered, it will throttle its performance to remain within its operational specifications. If that fails to keep it cool, it will simply shut down to protect itself.
    Avoid any clever third party hacks such as those intended to manipulate the exhaust fan speed. Doing that will only draw in more environmental contaminants than would normally occur, and could conceivably render its warranty void.
    No battery works as well as a brand new one. They are all wear items that will require eventual replacement. Usually, by that time your Mac will be so old you'll want to replace it anyway.
    It's obviously an unscientific observation, but I find that the less people obsess about their Macs, the longer they tend to last. Expect your Mac to serve you well until 2020, at least. By that time who knows what we'll be doing with them.

  • How hard can it be to get a price for DPS Enterprise?

    Is the Enterprise License made from Unicorn tears or what?
    We have now spent  three hours on three separate calls to Adobe enquiring about the cost of an Enterprise license. We are Adobe Pro users, and find it bizarre that no-one in the wide Adobe world appears to be able to be prepared to even guestimate a price for us.
    But Adobe's support network is really good at passing us on to another department, in another country, to another department in another country until "our office is now closed".
    Today, on attempt no 3 the Adobe sales person cut me off. She then  called my phone and left me a voicemail message, during which she put my voicemail on hold. Yes, she put my voicemail on hold…

    Hi Renny,
    I work for MEI, Adobe's top reseller for the DPS product. We're working with a number of customers moving from Pro to Enterrpise and I'd be happy to help you as well. We also have some value-add products and services to help you make the most out of the DPS Enterprise platform like our recently announced MEI Portico solution.
    Please feel free to email me at the address below. I also sent you a PM with my cellphone.
    Best,
    Brett
    [email protected]

  • I just want to set my Jlabels coordinates, how hard can that be???? HELP

    hey, basically this is the first time ive ever touched java therefore bear with me. Basically all i want to do is set an images coordinates so its where i want it to be. i want the image to stay there permently.
    Please help
    import javax.swing.JFrame;
    import java.awt.image.BufferedImage;
    import javax.swing.Timer;
    import javax.swing.ImageIcon;
    import java.awt.FlowLayout;
    import javax.swing.JLabel;
    public class Main
    public static void main(String[] args)
    JLabel image=new JLabel(new ImageIcon("image.gif"));
    frame.add(image);
    rame.setVisible(true);

    hey, basically this is the first time ive ever
    touched java therefore bear with me. Basically all i
    want to do is set an images coordinates so its where
    i want it to be. i want the image to stay there
    permently.Two options.
    Option A:
    Use a null LayoutManager for your JFrame and explicitly set the bounds of the JLabel:
    frame.setLayout(null);
    image.setBounds(x,y,w,h);  // x,y,w,h are calculated by you somewhere else
    frame.add(image);Option B:
    Paint the image on the JFrame directly by overriding its painting code.
    Neither option is a good idea. What exactly are you trying to create?

Maybe you are looking for

  • Get PricingConditions values from PricingConditionPanel class method?

    Hi, The class PricingConditionPanel returns the arraylist of the pricing onditions on the item with method getPricingConditions(); through the interface PricingContainer. I am able to get the values in the arraylist returned by the class. It actually

  • IPad 30-pin Port Seemingly Broken; Unexportable Data must be Backed Up

    Hello everyone. I come here in desperation. My iPad's 30-pin port recently decided to stop functioning properly: 1) When plugged into a "dumb" power source like a USB/AC block it does the "Not Charging" message, even on power sources it never used to

  • LiveCycle Designer ES 8.2  Numerisches Feld

    Hallo, ich habe ein Problem mit einem Numerischen Feld. Dieses akzeptiert z. B. keine fogende Nummer: 1.91.03.001.02.01 Welches Muster muss ich eintragen, damit nach dem Eintrag diese Nummern akzeptiert werden und nicht nach Eingabe nur die 1 erschei

  • HT4236 deleting albums in Gallery

    I have created albums in my gallery from images synced from my PC. As I was just getting accustomed to a new iPad these albums were not set up in the way I wanted or with the content I wanted.  I want to remove these albums from my ipad but there see

  • WebUI Integrated into Portal

    We have been able to successfully integrate the WebUI into the portal by exporting the business roles and importing into the EP. My question is, when doing this, do we completely lose the L shape navigation area and remain stuck with the old style ta