HELP needed - I'm a newbie

D

Dale Packwood

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];
}
 
J

Joona I Palaste

Dale Packwood <[email protected]> scribbled the following
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.
 
J

John C. Bollinger

Dale said:
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
(e-mail address removed)
 
R

Roedy Green

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.
 
J

Joona I Palaste

Roedy Green <[email protected]> scribbled the following
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 ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Parthenogenetic procreation in humans will result in the founding of a new
religion."
- John Nordberg
 
D

Dale Packwood

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top