HELP needed - I'm a newbie

Discussion in 'Java' started by Dale Packwood, Oct 22, 2003.

  1. Hello,

    The problem I'm having is that the below piece of code go through the if
    statement twice and I can't fiqure out why. Could someone point me in the
    right direction. Thanks

    String from = fromdcntomcn.getFrompartnumber();
    String to = fromdcntomcn.getMcnnumber();

    String[] TOMCN = to.split("-");
    String[] FROMMCN = from.split("-");

    if (TOMCN[1].equals(FROMMCN[1])) {
    System.out.println("Nice Job. Family numbers match. Please
    continue. " + TOMCN[1]);
    }
    else {
    System.out.println( "Sorry the family numbers did not match.
    Please try again... " + TOMCN[1] + FROMMCN[1]);
    }
    return TOMCN[1];
    }
    Dale Packwood, Oct 22, 2003
    #1
    1. Advertising

  2. Dale Packwood <> scribbled the following
    on comp.lang.java.programmer:
    > Hello,


    > The problem I'm having is that the below piece of code go through the if
    > statement twice and I can't fiqure out why. Could someone point me in the
    > right direction. Thanks


    > String from = fromdcntomcn.getFrompartnumber();
    > String to = fromdcntomcn.getMcnnumber();


    > String[] TOMCN = to.split("-");
    > String[] FROMMCN = from.split("-");


    > if (TOMCN[1].equals(FROMMCN[1])) {
    > System.out.println("Nice Job. Family numbers match. Please
    > continue. " + TOMCN[1]);
    > }
    > else {
    > System.out.println( "Sorry the family numbers did not match.
    > Please try again... " + TOMCN[1] + FROMMCN[1]);
    > }
    > return TOMCN[1];
    > }


    This code you posted can't possibly perform the code inside the if
    block twice. In fact it can't possibly perform *any* part twice.
    Please post the minimal compilable snippet that exposes the problem.
    Copy&paste, do not retype.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "No, Maggie, not Aztec, Olmec! Ol-mec!"
    - Lisa Simpson
    Joona I Palaste, Oct 22, 2003
    #2
    1. Advertising

  3. Re: HELP needed - I'm a newbie Nevermind

    Nevermind I found the problem. It was in my other class file...



    "Dale Packwood" <> wrote in message
    news:bn6f5r$sf7$...
    > Hello,
    >
    > The problem I'm having is that the below piece of code go through the if
    > statement twice and I can't fiqure out why. Could someone point me in the
    > right direction. Thanks
    >
    > String from = fromdcntomcn.getFrompartnumber();
    > String to = fromdcntomcn.getMcnnumber();
    >
    > String[] TOMCN = to.split("-");
    > String[] FROMMCN = from.split("-");
    >
    > if (TOMCN[1].equals(FROMMCN[1])) {
    > System.out.println("Nice Job. Family numbers match. Please
    > continue. " + TOMCN[1]);
    > }
    > else {
    > System.out.println( "Sorry the family numbers did not match.
    > Please try again... " + TOMCN[1] + FROMMCN[1]);
    > }
    > return TOMCN[1];
    > }
    >
    >
    Dale Packwood, Oct 22, 2003
    #3
  4. Dale Packwood wrote:
    > The problem I'm having is that the below piece of code go through the if
    > statement twice and I can't fiqure out why. Could someone point me in the
    > right direction. Thanks
    >
    > String from = fromdcntomcn.getFrompartnumber();
    > String to = fromdcntomcn.getMcnnumber();
    >
    > String[] TOMCN = to.split("-");
    > String[] FROMMCN = from.split("-");
    >
    > if (TOMCN[1].equals(FROMMCN[1])) {
    > System.out.println("Nice Job. Family numbers match. Please
    > continue. " + TOMCN[1]);
    > }
    > else {
    > System.out.println( "Sorry the family numbers did not match.
    > Please try again... " + TOMCN[1] + FROMMCN[1]);
    > }
    > return TOMCN[1];
    > }


    There is no looping construct in the posted code, and there is a return
    statement that will always be executed unless an exception occurs. If
    the code is being executed more than once then the method that contains
    it is being invoked more than once.


    John Bollinger
    John C. Bollinger, Oct 22, 2003
    #4
  5. Dale Packwood

    Roedy Green Guest

    Re: HELP needed - I'm a newbie Nevermind

    On Wed, 22 Oct 2003 11:46:04 -0700, "Dale Packwood"
    <> wrote or quoted :

    >Nevermind I found the problem. It was in my other class file...


    OH NO YOU DON'T. When you have pestered the group for the solution to
    a problem and you find it yourself, you owe it to the group to post
    the solution. Why? They may have a similar mystery in their own code
    some day and will remember what the cause was.

    What you are doing is like ripping the last pages out of mystery
    novels at the library.


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Oct 22, 2003
    #5
  6. Re: HELP needed - I'm a newbie Nevermind

    Roedy Green <> scribbled the following
    on comp.lang.java.programmer:
    > On Wed, 22 Oct 2003 11:46:04 -0700, "Dale Packwood"
    > <> wrote or quoted :
    >>Nevermind I found the problem. It was in my other class file...


    > OH NO YOU DON'T. When you have pestered the group for the solution to
    > a problem and you find it yourself, you owe it to the group to post
    > the solution. Why? They may have a similar mystery in their own code
    > some day and will remember what the cause was.
    >
    > What you are doing is like ripping the last pages out of mystery
    > novels at the library.


    Normally I would agree with you, but this doesn't seem like a common
    problem, as it seems to rely pretty heavily on that other class file
    that Dale wrote. And that class file might be very complicated. So,
    the point is, other programmers are very unlikely to make the same
    mistake as Dale did, and so the mistakes they make can't be solved
    in the same way Dale solved his.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "Parthenogenetic procreation in humans will result in the founding of a new
    religion."
    - John Nordberg
    Joona I Palaste, Oct 22, 2003
    #6
  7. Re: HELP needed - I'm a newbie Nevermind

    Answer to the mystery novel

    The problem was in the other class file that I had calling out this method.
    I call the method twice instead of just once. That is why I'm still a
    newbie.

    -Dale
    "Joona I Palaste" <> wrote in message
    news:bn6s5j$9pa$...
    > Roedy Green <> scribbled the following
    > on comp.lang.java.programmer:
    > > On Wed, 22 Oct 2003 11:46:04 -0700, "Dale Packwood"
    > > <> wrote or quoted :
    > >>Nevermind I found the problem. It was in my other class file...

    >
    > > OH NO YOU DON'T. When you have pestered the group for the solution to
    > > a problem and you find it yourself, you owe it to the group to post
    > > the solution. Why? They may have a similar mystery in their own code
    > > some day and will remember what the cause was.
    > >
    > > What you are doing is like ripping the last pages out of mystery
    > > novels at the library.

    >
    > Normally I would agree with you, but this doesn't seem like a common
    > problem, as it seems to rely pretty heavily on that other class file
    > that Dale wrote. And that class file might be very complicated. So,
    > the point is, other programmers are very unlikely to make the same
    > mistake as Dale did, and so the mistakes they make can't be solved
    > in the same way Dale solved his.
    >
    > --
    > /-- Joona Palaste () ------------- Finland --------\
    > \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    > "Parthenogenetic procreation in humans will result in the founding of a

    new
    > religion."
    > - John Nordberg
    Dale Packwood, Oct 23, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benny

    xml newbie help needed!!!

    Benny, Nov 16, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    441
    Steve Haun
    Nov 16, 2003
  2. Trevnal
    Replies:
    4
    Views:
    409
    Harald
    May 1, 2005
  3. Replies:
    1
    Views:
    849
    Ray in HK
    Jun 10, 2005
  4. Ryan Macy

    Ideas needed & help needed!

    Ryan Macy, Jul 19, 2006, in forum: Ruby
    Replies:
    2
    Views:
    500
    Ryan Macy
    Jul 19, 2006
  5. LeTubs
    Replies:
    6
    Views:
    117
    Tad McClellan
    Jan 25, 2004
Loading...

Share This Page