Creating a string, reversing it, and than comparing with another one

// get input
InputStreamReader is = new InputStreamReader (System.in);
BufferedReader in = new BufferedReader (is);
String str = in.readLine ();
// get length of input
int len = str.length ();
// reverse the input
//String rts = "";// = new String[len];
//for (int i=0; i<len; i++) rts.concat (str.charAt (len - i));
StringBuffer rts = new StringBuffer(str).reverse ();
// display the reversed string
System.out.println(rts + "\n");
// end if input was "tiuq"
if (rts == "quit") break;I am accustomed to C language, now trying to learn Java. The string operations are still too much for me.
In the code above, I managed to reverse my string using a "StringBuffer" object (still i don't know what it is), but couldn't compare it with "quit" constant. Compiler give "imcompareble types" error message.
*1) How can I compare a StringBuffer with a constant?*
On the other hand, why didn't my for loop didn't work (the commented-out one)? This time compiler says "java.lang.String cannot be applied to (char)".
*2) How can I make this method work?*
I also tried something like this:String[] rts = new String[len];
for (int i=0; i<len; i++) rts[i] = str[len - i];But in this way, I couldn't find a way to compare str with the constant "quit".
*3) How can I compare a String with a constant?*
Can someone answer help me out on these 3 questions?

hkBattousai wrote:
@Skydev2u
Why did you use nested fors? It can already be done with only one for loop. I didn't understand your logic.
Anyway, my code works, and it is as follows:// get input
InputStreamReader is = new InputStreamReader (System.in);
BufferedReader in = new BufferedReader (is);
String str = in.readLine ();
// get length of input
int len = str.length ();
// reverse the input
StringBuffer rts = new StringBuffer(str).reverse ();
// display the reversed string
System.out.println(rts + "\n");
// end if input was "tiuq"
if (rts.toString().equals("quit")) break;What I want to learn is, isn't a way to realize this without using that StringBuffer thing? Can you propose a mathod that merely uses the String class?I used the nested loops because I thought it would make the code clearer but at the same time i didn't really understand what you were doing since I don't know much about StringBuffer class. But from your reply I see that it was not needed.
(The above stated is my best understanding of the concept. Use it as a guideline to answering your question)

Similar Messages

  • If I erase ex-admin user and replace it with another one, will the applications installed previously be still available?

    I am going to pass my MBP to a friend and I'm trying to erase all my personal data. I didn't find a better solution as to delete myself as an old User and create a brand new User with administrator rights. I wonder if my AppStore applications as well as some programs such as MS Office, Photoshop, etc. will still be available for a new user.

    Licensing on those programs belong to you and are not directly transferable. The correct way to do this is by reinstalling the OS and shutting the Mac off before first start, so the new user can register his info.

  • How do I unregister a serial number for LR and replace it with another one?

    Hello
    I got LR3 with my Leica M9. Now I sold my M9 and I'm waiting for the next Leica M to arrive in the next few months. Since LR is more or less part of the Leica-Software, I sold it with it and for the time, while I waiting for the next M, I bought a new LR-License.
    Now I want to give the buyer of my camera the license number for the LR3, that came with the M9 and the LR4-update to it, so he can use it with the camera.
    My problem is now, that I can not unregister the license-number in my Adobe-account for the old LR. How do I do that? After unregistering I want to install my new LR, that just arrived today and register it, but I'm afraid, that I have two registered LR4 versions then and can't give the solde one to the buyer of the camera.
    Thanks for any help and best regards!

    Excerpt from the Lr EULA:
    4.4 No Transfer. YOU MAY NOT RENT, LEASE, SELL, SUBLICENSE, ASSIGN OR TRANSFER YOUR RIGHTS IN THE SOFTWARE, OR AUTHORIZE ANY PORTION OF THE SOFTWARE TO BE COPIED ONTO ANOTHER INDIVIDUAL OR LEGAL ENTITY'S COMPUTER EXCEPT AS MAY BE PERMITTED HEREIN. You may, however, transfer all your rights to use the Software to another individual or legal entity provided that: (a) you also transfer this agreement, (ii) the serial number(s), the Software and all other software or hardware bundled, packaged or pre-installed with the Software, including all copies, upgrades, updates and prior versions, and (iii) all copies of font software converted into other formats to such individual or entity; (b) you retain no upgrades, updates or copies, including backups and copies stored on a computer; and (c) the receiving party accepts the terms and conditions of this agreement and any other terms and conditions under which you purchased a valid license to the Software. NOTWITHSTANDING THE FOREGOING, YOU MAY NOT TRANSFER EDUCATION, PRE-RELEASE, OR NOT FOR RESALE COPIES OF THE SOFTWARE. Prior to a transfer Adobe may require that you and the receiving party confirm in writing your compliance with this agreement, provide Adobe with information about yourselves, and register as end-users of the Software. Allow 4-6 weeks to transfer. Please visit http://www.adobe.com/supportor contact Adobe's Customer Support Department for more information."
    For full text of EULA see here: http://labs.adobe.com/technologies/eula/lightroom.html

  • If I create a new Apple ID and I delete the old one, Will I lose my purchases and data?

    If I create a new Apple ID and I delete the old one, my books, songs, docs and all the data that my old Apple ID contained including my purchased Apps will appear in my new Apple ID and its associated Icloud?
    I want to create a new Apple ID but do not lose my data and purchases, How could I do it?

    Are you entering your Existing Email Address for which you have Access and also are you Entering the Password which Matches Apple Requirement ?
    Enter the Email Address that you already have (like Gmail, Yahoo, MSN, Live, etc) but you have never used it for creating Apple ID before.
    Passwork Requirement is Minimum 8 Characters, Alpha Numeric and Password should Content atleast 1 Upper Case and 1 Lower Case Letter. You will find the more detail on the same page when Creating Apple Id and iTunes will give you Error if the Password you enter does not match their requirement.

  • Can I creat an new iCloud account and make it the primary one for my backups and buy extra iCloud storage for it?  Thank you

    Can I creat an new iCloud account and make it the primary one for my backups and buy extra iCloud storage for it?  Thank you

    Hey Hindfromlondon,
    Welcome to Apple Support Communities.  Since you are posting here, I take it you already have an Apple ID.  
    You can setup that Apple ID to work with iCloud.  See:
    Set up your Apple ID for iCloud and iTunes - Apple Support
    And you usually want to stick with one Apple ID as having multiples can cause confusion (especially with purchases).
    Frequently asked questions about Apple ID - Apple Support
    What is an Apple ID?
    An Apple ID is a user name you use for everything you do with Apple. Creating an account for an Apple service, such as the iTunes Store or the App Store, creates an Apple ID. Apple ID allows you to access other Apple services. You don't have to create a new account for each service—just use your Apple ID.
    For a complete list of all of the places you can use an Apple ID, see Where do I use an Apple ID.
    and further down:
    I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID?
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs. 
    If you are wondering how using multiple Apple IDs relate to iCloud, see Apple IDs and iCloud.
    Regarding iCloud storage check out
    iCloud storage upgrades and downgrades - Apple Support
    I encourage you to read all about it as there's lots of information out there.
    Take care,
    Nubz

  • Is it possible to create a playlist and share it with another itunes user?

    Is it possible to create a playlist and share it with another itunes user?

    try this out
    Select distinct   
    v_R_System.Netbios_Name0 AS [Computer Name],  
    v_GS_COMPUTER_SYSTEM.UserName0 AS [User Name]
     from v_R_System
    left join v_GS_COMPUTER_SYSTEM on (v_GS_COMPUTER_SYSTEM.ResourceID = v_R_System.ResourceID) 
    inner join v_fullcollectionmembership as b on (b.ResourceID = v_R_System.ResourceID) 
    left join v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP ON v_GS_SYSTEM_CONSOLE_USAGE_MAXGROUP.ResourceID = v_R_System.ResourceID
            inner join v_GS_SYSTEM e on e.resourceid = b.resourceid
     Where
    b.CollectionID = @collectionid
    Blog: http://theinfraguys.com
    Follow me at Facebook
    The Infra Guys Facebook Page
    Please remember to click Mark as Answer on the answer if it helps you in anyway

  • HT4061 How do you change your phone number than is in your iPad and replace it with right one to receive and send messages?

    How do you change your phone number in your iPad messages and replace it with another number. In order to send and receive messages to the correct phone number?

    It's best to use an email address on the iPad.
    Using FaceTime http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime + iMessage: Setup, Use, and Troubleshooting
    http://tinyurl.com/a7odey8
    Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/TS4268
    iOS: FaceTime is 'Unable to verify email because it is in use'
    http://support.apple.com/kb/TS3510
    Using FaceTime and iMessage behind a firewall
    http://support.apple.com/kb/HT4245
    iOS: About Messages
    http://support.apple.com/kb/HT3529
    Set up iMessage
    http://www.apple.com/ca/ios/messages/
    iOS 6 and OS X Mountain Lion: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/HT5538
    How to Set Up & Use iMessage on iPhone, iPad, & iPod touch with iOS
    http://osxdaily.com/2011/10/18/set-up-imessage-on-iphone-ipad-ipod-touch-with-io s-5/
    Troubleshooting Messages
    http://support.apple.com/kb/TS2755
    Troubleshooting iMessage Issues: Some Useful Tips You Should Try
    http://www.igeeksblog.com/troubleshooting-imessage-issues/
    Setting Up Multiple iOS Devices for iMessage and Facetime
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
    FaceTime and iMessage not accepting Apple ID password
    http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/
    FaceTime, Game Center, Messages: Troubleshooting sign in issues
    http://support.apple.com/kb/TS3970
    Unable to use FaceTime and iMessage with my apple ID
    https://discussions.apple.com/thread/4649373?tstart=90
    How to Block Someone on FaceTime
    http://www.ehow.com/how_10033185_block-someone-facetime.html
    My Facetime Doesn't Ring
    https://discussions.apple.com/message/19087457
    Send an iMessage as a Text Message Instead with a Quick Tap & Hold
    http://osxdaily.com/2012/11/18/send-imessage-as-text-message/
    To send messages to non-Apple devices, check out the TextFree app https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8
    How to Send SMS from iPad
    http://www.iskysoft.com/apple-ipad/send-sms-from-ipad.html
    You can check the status of the FaceTime/iMessage servers at this link.
    http://www.apple.com/support/systemstatus/
     Cheers, Tom

  • How do you remove a person from a photo and replace her with another person

    How do you remove a person from a photo and repalce her with another person.

    There are many tool and "tricks" to accomplish this manipulation. However, depending on the image one technique might be more appropriate than an other. And then there is the question of how to do it "skillfully". For example, the shadows in the person that is being substituted might be different than in the original image creating the obviously "photoshopped" look.
    Doing an Internet search on your posting title brings up lots of examples.

  • I have an extensive aperture library on my computer's hard drive and I want to break it up into separate smaller libraries on external hard drives.  How do I take projects from one library and add them to another one?

    I have an extensive aperture library on my computer's hard drive and I want to break it up into separate smaller libraries on external hard drives.  How do I take projects from one library and add them to another one?

    Coastal,
    Frank gave you the exact answer to your question. 
    However, I would like to ask if you are indeed asking the right question.  Do you really want different libraries?  The implications are that you have to "switch" libraries to see what's in the others, and so that your searches don't work across all of your pictures?  If so, then you asked the right question.  If not, you may be more interested in relocating your masters to multiple hard drives so your library gets smaller, instead of breaking up the library.
    nathan

  • I have a Ipod Nano and want to get another one , and use both. Can I use the same computer and library for both?

    I have a Ipod Nano and want to get another one , and use both. Can I use the same computer and library for both?

    Yes

  • My iphone is synced and backed up with another computer which is now broken... and i have synced it with a new one but when i want to do anything itunes says all data will be erased and replaced with the current itunes library?what do i do?

    my iphone is synced and backed up with another computer which is now broken...i have synced it with my new computer  but it hasnt transfered anything over to itunes and when i try to add anything to my iphone it says all data will be erased and replaced with the current itunes? i dont want to lose all my apps and music.... i dont know how to go around this problem? i want to back it all up and sync it properly to my new computer so that is now my main computer , so i can add ring tones and music etc with out it erasing everything ive got. any answers would be great and muchly appreciated. thanks, im not sure what operating system my iphone has either.....

    It has always been very basic to always maintain a backup copy of your computer for just such an occasion.
    Use your backup copy of your computer to put everything on the new one.
    It sounds like you have failed to do this, which is not good at all.
    You will have to transfer your itunes purchases from your iphone.  Authorize your computer for your itunes account 
    About iTunes Store authorization and deauthorization
    Open itunes, plug in iphone, do NOT sync, click File>Transfer Purchases
    When you do sync you will lose your pics ( photo library - synced from your old computer), your itunes content ( music, apps, videos,etc) , your contacts and your calendars.  So do NOT sync yet.  This is why a backup copy is so important.
    Enter one unique contact and calendar entry on your computer.
    When you first sync, you should get the option to merger the data.  Choose it.
    If you want your pics, then you will need to e-mail them to yourself before you sync.  They will not be of the original quality as they are reduced when synced to iphone.
    When all is as goos as it can be, then backup your computer, and always maintain the backup.

  • I had to replace my i4s with another one from the apple store.shouldn't i be able to go to the cloud to get all my contact info and other stuff that was stored in the cloud from the first phone?

    i had to replace my i4s phone with another one from the apple store. i need to download all my contact info and other stuff from the cloud to my new phone.i see a screen that says  RESTORE I PHONE   and are you sure you want to restore the iphone to its facory settings?  all of your media and other data will be erased. they i tunes will verify restore with apple. After this you will have the option to restore your contacts and other settins.  The question is will it restore my first phones info?  I am hesitant to delete anything  lol.

    No. If you made your backup to iCloud, iTunes will not restore from an iCloud backup. See:
    iOS: Backing Up and Restoring Data to a New Device

  • Iphoto:  When I choose a photo and click on it, another one appears.

    When I choose on a photo in Iphoto and click on it, another one appears.

    Back up your iPhoto library, Depress and hold the option (alt) and command keys and launch iPhoto - rebuild your thumbnails - this may take a few trys
    LN

  • How to synchronise a calendar on one computer and the music on another one

    As I don't want to import my music on the business computer, I'm wondering if it is possible to synchronise a calendar on one computer (business) and the music on another one (private) ? Does anyone have an answer ? I tried with itunes homesharing but everytime i try to synchronise only the calendar, it deletes all my music on my iphone.

    Turn home sharing off & uncheck content like music, videos & apps on the computer you only want to sync your calendar with. You can sync your contacts & calendars with multiple computers, content like music with only one.

  • I have a shuffle. When I plug it into Itunes, it tells me that it has not been ejected properly, and it will not recognize the Ipod. I have turned off the computer, and tried this with another shuffle with the exact same results. Any ideas?

    I have a shuffle. When I plug it into Itunes, it tells me that it has not been ejected properly, and it will not recognize the Ipod. I have turned off the computer, and tried this with another shuffle with the exact same results. Any ideas?

    Do you remeber the exact (or close to it) wording of the error message?
    Try manually placing the iPod in Recovery mode and then try to restore
    Next try DFU mode.
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    You can also try another computer  to help determine if you have an iPod or computer problem.

Maybe you are looking for

  • Impli?it import in JSP

    Hi,           Could anybody clear the following question? Which way does jsp compiler make           import of packages on weblogic 6.0? I looked through JSP examples and did           not find any import declaration in some of them, but there were s

  • "Roll over to try, click to apply" does nothing

    I just did the latest Firefox update - no problems - but once again, after the last 2 or 3 or more updates, the "Roll over to try, click to apply" option to try out the new 'personas" does nothing. I remember when they first came out and I could roll

  • Calling IP from a Session Bean

    I am looking to put some security on our EJBs based on the callers IP address. I can't seem to figure out how to get the calling IP from within the session bean. Does security need to be enabled to get this information? Is there something that I am m

  • Script for saving GIF with Animation Loop Endless

    Hi, I am searching for a way to use  "save for web" in a Photoshop CC Script. I already found how to use the "save for web" using Script, but now i am stuck, because i cannot find any information on how to set that the animation, i want to save as a

  • Unable to delete credit memo request

    Hi all, I created a Credit memo request ( Sales document ) and I created Credit memo (Billing) for that.I dont want these both now.Hence I cancelled the credit memo first and now I am trying to delete the Credit memo request.System is not deleting.It