I really can't understand how this recursive works??

Hi all,
I have got a recursive function that checks for palendrome string. But it is confusing. I know that a string is palenromme if it is empty or has a char or first char and last one are same and middle is palindromme too.
but can't understand how this function works.
class Palindromme
     boolean palindrom(String s)
          if (s.length() <= 1 || s.equals(null) || s=="") //this is the stopping point
               return true;
          else
          {                    //recursive definition
               return ( s.charAt(0) == s.charAt(s.length()-1) ) && palindrom(s.substring(1,s.length()-1));
specially i don't know how palindrom(s.substring(1,s.length()-1)); is working cause it has to be increased for each loop.
abdul
PS: actually i don't know how recursion works from Data structure point of view

Hi,
ok your palindrome is : "otto"
return ( s.charAt(0) == s.charAt(s.length()-1) ) && palindrom(s.substring(1,s.length()-1));
              o                     o                                   tt
so first part is true                                        
in the second part palindrom is called again but with the remaining tt
so second time :
return ( s.charAt(0) == s.charAt(s.length()-1) ) && palindrom(s.substring(1,s.length()-1));
               t                     t                                 ""
Third time:
if (s.length() <= 1 || s.equals(null) || s=="") //this is the stopping point
return true;after all for otto the recusion is:
return ( s.charAt(0) == s.charAt(s.length()-1) ) && s.charAt(1) == s.charAt(s.length()-2) ) && nothing left of otto);
Phil

Similar Messages

  • How much does this cost? & I still can't understand how this work

    How much does this cost? & I still can't understand how this work

    Hello mkopti,
    ePrint is a free feature include on most of our wireless printers that are e-all-in-one enabled. It allows you to register your printer on HP's website http://www.eprintcenter.com and create an account. Once an account has been created you can enable the web services feature, after connecting to a valid network with internet access, which will print off a registration code you can use to add the printer to your account and customize an email address for the printer. This allows you to print to the printer from virtually anywhere simply by sending an email to the printers email address and when it is received it will print.
    Most of these printers are also Airprint enabled meaning you can print locally from the same network on the iPad, iPod, and iPhone (version 4.3.2 and higher) by using the built in "Print" command in the idevices.
    If you have any other questions or need clarification feel free to reply to this post and I will try to answer any questions you have.
    If I have solved your issue, please feel free to provide kudos and make sure you mark this thread as solution provided!
    Although I work for HP, my posts and replies are my own opinion and not those of HP.

  • Can't understand how this group by clause works

    The Schema is as below: (http://www.psoug.org/reference/rollup.html)
    CREATE TABLE grp_rep (
    person_id NUMBER(3),
    division VARCHAR2(3),
    commission NUMBER(5));
    INSERT INTO grp_rep VALUES (1,'SAM',1000);
    INSERT INTO grp_rep VALUES (2,'EUR',1200);
    INSERT INTO grp_rep VALUES (1,'EUR',1450);
    INSERT INTO grp_rep VALUES (1,'EUR',700);
    INSERT INTO grp_rep VALUES (2,'SEA',1000);
    INSERT INTO grp_rep VALUES (2,'SEA',2000);
    INSERT INTO grp_rep VALUES (1,'EUR',800);
    COMMIT;
    Query1:
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY person_id, ROLLUP (person_id, division);
    Query2:
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY division, ROLLUP (person_id, division);
    The results of query1 are okay. It has results from rollup and group by person_id.
    But, in Query2 results of rollup are missing and results of group by division is there.
    Anyone can explain how the group by clause works when there are multiple columns involving CUBE, ROLLUP and simple column names?
    Regards.

    Thank you shoblock!
    but, What i m really looking for is,
    How group by clause works when i add regular column along with RollUp in group by clause?
    I have understood simple group by clause like
    ...group by column1,column2,column3....
    n I also know simple rollup clauses like
    ...group by rollup(column1,column2,column3,...)
    But my Problem is how does this work:
    ...group by column2,rollup(column1,column2,...)
    ...group by column1,rollup(column1,column2,...)
    See below Results:
    Query1:
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY person_id,ROLLUP ( person_id, division );
    Result:
    PERSON_ID DIVISION SUM(COMMISSION)
         1      EUR      2950
         1     SAM      1000
         2      EUR      1200
         2      SEA      3000
         1           3950
         2           4200
         1           3950
         2           4200
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY division,ROLLUP ( person_id, division );
    Query2:
    SELECT person_id, division, SUM(commission)
    FROM grp_rep
    GROUP BY division,ROLLUP ( person_id, division );
    Result:
    PERSON_ID DIVISION SUM(COMMISSION)
    1 EUR 2950
    2 EUR 1200
         1 SAM      1000
    2 SEA 3000
    1 EUR 2950
    2 EUR 1200
    1 SAM 1000
    2 SEA 3000
    EUR 4150
    SAM 1000
    SEA 3000
    guys, help me make understand above results!
    Regards.

  • Hey i am unfamiliar with how to use icloud for storage. Can some one slowly( lol ) help me to understand how this thing works. I also need someone to help with how to transfer pics from your iphone to your flash drive.

    Hello i am needing some assistance as i am not very good at how the cloud works. I need to delete my account and start over.  I don't want to loose all of the things that i have on phone. Help!

    Slowly
    http://www.apple.com/icloud/features/
    but surely
    http://www.gottabemobile.com/2011/10/18/how-to-sync-email-contacts-and-calendar- with-icloud/
    we will come
    http://transfer-iphone-contacts.blogspot.com/p/iphone-contacts-sync-via-icloud.h tml
    to understanding
    http://support.apple.com/kb/PH12519
    on how icloud sync and backup work.
    http://www.apple.com/support/icloud/backup/
    http://support.apple.com/kb/ht1766
    And here we will find instructions on how to backup (import) pictures to computer, cause there is no direct transfer to flash drive.
    http://support.apple.com/kb/ht4083

  • [SOLVED] Can't understand how `install` command works

    Hi there:
    I'm trying to make a PKGBUILD for pgModeler, which comes pre-compiled, so I think what I should do is to move the application directory completely to /opt/pgmodeler and make a symbolic link from /usr/bin to the /opt/pgmodeler/start-pgmodeler.sh script. So, i just wrote this:
    pkgname=pgmodeler
    pkgver=0.4.1
    pkgrel=1
    pkgdesc="An open source tool for modeling PostgreSQL databases"
    arch=('x86_64')
    url="http://pgmodeler.com.br"
    license=('GPL3')
    source=("http://www.pgmodeler.com.br/releases/$pkgname-$pkgver-linux64.tar.gz" "pgmodeler.desktop")
    md5sums=('574887c35bc9e0a1bc65f8d4494200bb' '1f3ebda62e941ea7ea17cfb609cc392e')
    depends=(libpqxx)
    package() {
    install -Dm644 "$srcdir/$pkgname-$pkgver-linux64" "$pkgdir/opt/$pkgname"
    install -Dm644 "$srcdir/$pkgname.desktop" "$pkgdir/usr/share/applications/$pkgname.desktop"
    install -Dm644 "$srcdir/$pkgname-$pkgver-linux64/pgmodeler_logo.png" "$pkgdir/usr/share/pixmaps/$pkgname.png"
    chmod 755 "$pkgdir/opt/$pkgname/start-pgmodeler.sh"
    ln -s "$pkgdir/opt/$pkgname/start-pgmodeler.sh" "$pkgdir/usr/bin/$pkgname"
    But it fails in the first line of the package() function:
    [tae@localhost pgmodeler]$ makepkg -s
    ==> Making package: pgmodeler 0.4.1-1 (Sun Mar 17 23:03:08 CLST 2013)
    ==> Checking runtime dependencies...
    ==> Checking buildtime dependencies...
    ==> Retrieving Sources...
    -> Found pgmodeler-0.4.1-linux64.tar.gz
    -> Found pgmodeler.desktop
    ==> Validating source files with md5sums...
    pgmodeler-0.4.1-linux64.tar.gz ... Passed
    pgmodeler.desktop ... Passed
    ==> Extracting Sources...
    -> Extracting pgmodeler-0.4.1-linux64.tar.gz with bsdtar
    ==> Removing existing pkg/ directory...
    ==> Entering fakeroot environment...
    ==> Starting package()...
    install: omitting directory ‘/home/tae/GitHub/pgmodeler/src/pgmodeler-0.4.1-linux64’
    ==> ERROR: A failure occurred in package().
    Aborting...
    This is my first PKGBUILD and I'm trying to decipher how to make it by looking at this files: https://aur.archlinux.org/packages/dr/dropbox/PKGBUILD and https://aur.archlinux.org/packages/op/opcion/PKGBUILD and I never used the install command before so I'm pretty lost.
    Thanks beforehand.
    Last edited by Tae (2013-03-19 12:44:45)

    Thanks to all. I learned a couple of stuff, but I still have no luck. This is what I've tried:
    I wrote install -d "$pkgdir/opt" in the first line of the package() function before ask, but it didn't make any difference. In fact, I'm not sure what it does (from its man page: treat all arguments as directory names; create all components of the specified directories).
    I modified the function with all your suggestions, and now it looks:
    package() {
    cp -R "$srcdir/$pkgname-$pkgver-linux64" "$pkgdir/opt/$pkgname"
    chmod 644 "$pkgdir/opt/$pkname/"
    chmod 755 "$pkgdir/opt/$pkgname/start-pgmodeler.sh"
    install -Dm644 "$srcdir/$pkgname.desktop" "$pkgdir/usr/share/applications/$pkgname.desktop"
    install -Dm644 "$pkgdir/opt/$pkgname/pgmodeler_logo.png" "$pkgdir/usr/share/pixmaps/$pkgname.png"
    ln -s "/opt/$pkgname/start-pgmodeler.sh" "$pkgdir/usr/bin/$pkgname/"
    but I get:
    $ makepkg -s
    ==> Making package: pgmodeler 0.4.1-1 (lun mar 18 20:33:53 CLST 2013)
    ==> Checking runtime dependencies...
    ==> Checking buildtime dependencies...
    ==> Retrieving Sources...
    -> Found pgmodeler-0.4.1-linux64.tar.gz
    -> Found pgmodeler.desktop
    ==> Validating source files with md5sums...
    pgmodeler-0.4.1-linux64.tar.gz ... Passed
    pgmodeler.desktop ... Passed
    ==> Extracting Sources...
    -> Extracting pgmodeler-0.4.1-linux64.tar.gz with bsdtar
    ==> Removing existing pkg/ directory...
    ==> Entering fakeroot environment...
    ==> Starting package()...
    cp: cannot create directory ‘/home/tae/GitHub/pgModeler/pkg/opt/pgmodeler’: No such file or directory
    ==> ERROR: A failure occurred in package().
    Aborting...
    Here I can't understand why it tries to create /opt/pgmodeler inside the pkg/ directory. For what I found in other PKGBUILDs and from the $pkgdir definition of the PKGBUILD man page (This contains the directory where makepkg bundles the installed package (this directory will become the root directory of your built package)) I though it will be the root directory.
    So I removed all the $pkgdir from the function and now I get this error:
    mkdir: cannot create directory ‘/opt/pgmodeler/’: Permission denied

  • I don't understand how this Forum works

    I have a question getting the proper version of Flash Player for my computer.  So I went to the Flash Player forum and typed my question into the question box. 
    But all I received was a notice saying that no similar questions were found (or something to that effect).  In other words, it did not let me ask my question to the Adobe FP community--it just did a run of the keywords in previous posts.
    I need to ask my question to the Adobe community and have just spent half hour going around in circles.  Can someone please tell me what I'm doing wrong? Thanks.

    Because they want very few people to use their forums so that answering the questions becomes as easy as possible.
    That has not been the impression left on me. Recently, Adobe initiated a special department, to better manage the forums, as Adobe realizes the service that they provide. Much has been done to simplify, and coordinate the tasks of using the forums, with some fairly major re-designs.
    Have all those efforts been perfect? I rather doubt it, but the process is on-going, with many discussions on how to make the forum "experience," both easier and more satisfying to users - both those who post with problems and questions, and for those who answer the questions. Not every change has improved things for everyone, and I have had a few complaints on some. Still, the effort (and expense) is being put forth. Many are working very hard, and there have been improvements, with more to come. The forums will never be perfect for all users. That is just the way that it is. However, with a focus on "the greater good" of the "majority," then that might be, as good as it gets.
    Hunt

  • I would like to understand how merging cells works

    I am trying to reduce nine fields, into three, but can't understand how merging cells works. Because sometimes it will allow me to merge cells, and at other times the word merge is greyed out
    Regards Lee

    The User Guide, which you can download using the link in the Help menu, explains merging cells pretty clearly.
    I suspect the relevant line to your problem is:
    "The group of cells you choose must form a rectangle, and they must be all body cells, all header cells, or all footer cells."
    The merge option is probably greyed out because your selection includes both header and body cells.
    I think there is a general feeling among users that merging cells should be avoided because it breaks some operations like sorting tables.

  • Things have really changed.  I can't understand how Apple could release the Lion OS as buggy as it is ?  It's like reliving the nightmare of my PC days and the Microsoft crap !  Do I have to wipe the hardrive before reinstalling Snow Leopard ?  Comments..

    Things have really changed.  I can't understand how Apple could release the Lion OS as buggy as it is ?  It's like reliving the nightmare of my PC days and the Microsoft crap !  Do I have to wipe the hardrive before reinstalling Snow Leopard ?  The amazing thing is that when I installed Snow Leopard not a hitch, ever !    My trust in Apple is gone and believe me I will think twice before doing anymore OS upgrades, **** I can go back to the PC for a lot less money.

    Adios baby! Enjoy that PC!

  • Recently updated Numbers to Version 3.5.2 and now also seem to have Numbers Version 2.0 on my launchpad? Can anyone explain how this has happened - how do I get rid of it?

    Recently updated Numbers to Version 3.5.2 and now also seem to have Numbers Version 2.0 on my launchpad? Can anyone explain how this has happened - how do I get rid of it? Not able to move to Trash.

    What is strange however is that my iMac is only a few months old and they all were upgraded to V3.x just a few months ago - with all Apps for iWork removed at that time.
    Unless you did something specific to remove the old versions of the iWork apps (not advisable) then, as Wayne points out, they were not actually removed from your Mac, just moved into that subfolder within your main Applications folder.
    I originally downloaded Numbers 2.x from the App Store (i.e. didn't install from a disk). I still have it on my Mac.  But only Numbers 3.x appears in Launchpad.
    I don't know whether this will help, but in Mac App Store you might try clicking 'Account' under 'Quick Links' on the right, signing in with your password, and clicking the 'Reset' button to the right of 'Reset all warnings for buying and downloading'.  Sometimes the App Store gets a little confused. It's possible Launchpad may be taking its cue from the App Store in showing that old version of Numbers.
    By Launchpad I assume you really mean Launchpad, not the Dock.  I usually use the Dock. If that's what you're using too, then of course you can just drag the icon for the old Numbers off the Dock and it will vanish. (But the Numbers 2.3 application will still be there in that subfolder when you need it.)
    SG

  • Can anyone help me understand how font sizes work in Mail?

    Hi
    I am used to writing and sending emails in Arial 10 (on my PC using Outlook) - it seems like a professional sort of size to send to people.
    So I have set the Mail Preferences Fonts to Arial 10 for the message font
    But when I receive emails, the font is so small I can barely read it. I have a new 24" iMac and just cannot get to grips with keeping font sizes at a reasonable level between applications. And I though Mac was supposed to be joined up....
    As I write the text of this posting, the font is a good size to read (although still looks blurred - see my other postings) - it is in Arial which I want.... But I cannot get Mail to wrk in the same way.
    I do not want to change the font size to the email messages to a bigger font size, as I want my outgoing messages to be received in font size 10.
    Please help me understand how this is all supposed to work in MAC? It was all so easy on a PC!

    No, it is one of several unfathomable shortcomings in Mail that you are unable to set a minimum text viewing size. I too have 24in iMac and I have to enlarge each incoming message manually using Cmd+ and this is frankly Stone Age stuff, especially when dealing with hundreds of emails every day. Another very poor alternative is to use Ctrl and the scroll wheel to zoom in but your head will soon be spinning as the screen moves around.
    FWIW, I am also dismayed that Apple has disabled the Contextual Menu in 3 of the 4 mail address fields. There must be some obscure justification for limiting CM copy and paste to just the Subject field but I just think it's risible.
    And why can't I save a message I have just written to a place of my choosing? Instead I must save it to the Drafts folder or send it first and then Save As from the Sent mailbox. Is this someone's idea of fun?
    I could go on about Mail's shortcomings but that's enough ranting for now...
    Simon

  • HT1665 I am trying to connect my Samsung Bluetooth device with my new Iphone 4S.  Can anyone explain how this is done?

    I am trying to connect my Samsung Bluetooth device to my new Iphone 4s. Can anyone explain how this is don?

    Which Samsung Bluetooth device?
    Please note that the iPhone will not pair with other phones, tablets, etc for purposes of file transfer.

  • I can't understand how to edit titles on the spine of books. Could anyone help me? Thanks.

    I can't understand how to edit titles on the spine of books. Could anyone help me? Thanks.

    the trouble is that on the spine of the book the title is cut off and I don't know how avoid it.
    I don't think you can, Fred. Pick a shorter title. And add the additional information by adding a subtitle on your title page. You can always add a second text box, using the "edit layout" panel.
    Regards
    Léonie

  • Trying to understand how MIDI Clock works in Logic

    Hi,
    I'm syncing a Roland MC-909 Groove Box with Logic.  I'm also using a MOTU MIDI Express interface.  The MC-909 syncs to Logic, thus it is in Slave mode. Under Preferences->Sync->MIDI Sync Project Settings, I've discovered something odd, and I'm trying to understand it.  It could be just a lack of understanding regarding the MIDI Spec.
    Under MIDI Clock, I necessarily need to set the destination to the MC-909.  I cannot use 'All'  or else the MIDI Express starts playing back at 8x the tempo set in Logic.  Not sure why this happens but its probably something weird with the MOTO interface.  Anyway in Logic, MIDI Time Code (MTC) is disabled, Song Position Pointer (SPP) is disabled, and MMC is disabled.
    So basically I'm only sending MIDI Clock to the MC-909.  Here's what is wierd:  As I locate to different places in the Arrange window (not in play mode), the MC-909 is locating to the correct time offset within the pattern!  This basically guarantees that you can start the Logic song anywhere, and the MC-909 will start playing back the pattern at the right time.  I don't understand how this can be happening given that I've disabled SPP in Logic.  The only sync communication between Logic and the MC-909 is MIDI Clock, but I don't believe that MIDI Clock is even capable of transmitting offset information that specifies the time-offset into a drum machine pattern, Does it?  Or is Logic sending SPP info as I click on different locations in the Arrange window?
    Another point, is that if I select to transmit MIDI Clock to another device other than the MC-909, but still using the MOTU MIDI Express, then the MC-909 plays back synchronously (i.e. its getting MIDI Clock from Logic, even though Logic isn't sending MIDI Clock to the MIDI port connected to the MC-909), but it does not track the pattern offset described in the previous paragraph.  The only way I can get the pattern offset to work, is if I select the MIDI Clock to be sent to the MIDI port connected to the MC-909.
    I would like to figure this out because I'm thiinking about buying an external MIDI synchronizer, but I don't want to lose the ability to have logic specify the offset into the pattern on the MC-909
    Thanks,

    Hi,
    I'm syncing a Roland MC-909 Groove Box with Logic.  I'm also using a MOTU MIDI Express interface.  The MC-909 syncs to Logic, thus it is in Slave mode. Under Preferences->Sync->MIDI Sync Project Settings, I've discovered something odd, and I'm trying to understand it.  It could be just a lack of understanding regarding the MIDI Spec.
    Under MIDI Clock, I necessarily need to set the destination to the MC-909.  I cannot use 'All'  or else the MIDI Express starts playing back at 8x the tempo set in Logic.  Not sure why this happens but its probably something weird with the MOTO interface.  Anyway in Logic, MIDI Time Code (MTC) is disabled, Song Position Pointer (SPP) is disabled, and MMC is disabled.
    So basically I'm only sending MIDI Clock to the MC-909.  Here's what is wierd:  As I locate to different places in the Arrange window (not in play mode), the MC-909 is locating to the correct time offset within the pattern!  This basically guarantees that you can start the Logic song anywhere, and the MC-909 will start playing back the pattern at the right time.  I don't understand how this can be happening given that I've disabled SPP in Logic.  The only sync communication between Logic and the MC-909 is MIDI Clock, but I don't believe that MIDI Clock is even capable of transmitting offset information that specifies the time-offset into a drum machine pattern, Does it?  Or is Logic sending SPP info as I click on different locations in the Arrange window?
    Another point, is that if I select to transmit MIDI Clock to another device other than the MC-909, but still using the MOTU MIDI Express, then the MC-909 plays back synchronously (i.e. its getting MIDI Clock from Logic, even though Logic isn't sending MIDI Clock to the MIDI port connected to the MC-909), but it does not track the pattern offset described in the previous paragraph.  The only way I can get the pattern offset to work, is if I select the MIDI Clock to be sent to the MIDI port connected to the MC-909.
    I would like to figure this out because I'm thiinking about buying an external MIDI synchronizer, but I don't want to lose the ability to have logic specify the offset into the pattern on the MC-909
    Thanks,

  • Documents/PPT for Understanding how SAP SRM works from SAP website

    Hi,
    Can some one help me in finding some docs/ppts which helps me to understand how SAP SRM working from SAP website.
    Regards,
    Manesh

    Hi, thanks for the response.
    This is what they get
    Fatal error: Call to a member function remove_all() on a non-object in .../.../.../welcome.php
    This error is not generated by SAP. It is shopping cart error.
    And here is the content of welcome.php
    <?php
      require("includes/application_top.php");
         $cart->remove_all();
        $hook = $_REQUEST['HOOK_URL'];
    ?>
    The value of HOOK_URL is empty
    <a href="index.php?HOOK_URL=<?php echo $hook; ?>">Start shopping here</a>
    Edited by: janjan123 on May 14, 2010 5:06 PM

  • Need to understand how ioctl errors work.

    I'm trying to understand how ioctl errors work. Who is responsible for returning a -1 for an error and passing the actual error number in errno? Do the functions miocack and miocnak play any part in this? Where can I find a desciption of miocack, miocnak?

    Hi
    The return value of ioctl is dependent upon the called device
    control function. If for some reason the ioctl is not able to
    call the corresponding device control function then a return
    value of -1 is returned by the kernel and the errno set to
    indicate the type of error.
    -Manish Dixit
    Sun - dts

Maybe you are looking for