Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > HELP needed - I'm a newbie

Reply
Thread Tools

HELP needed - I'm a newbie

 
 
Dale Packwood
Guest
Posts: n/a
 
      10-22-2003
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];
}


 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      10-22-2003
Dale Packwood <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"No, Maggie, not Aztec, Olmec! Ol-mec!"
- Lisa Simpson
 
Reply With Quote
 
 
 
 
Dale Packwood
Guest
Posts: n/a
 
      10-22-2003
Nevermind I found the problem. It was in my other class file...



"Dale Packwood" <(E-Mail Removed)> wrote in message
news:bn6f5r$sf7$(E-Mail Removed)...
> 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];
> }
>
>



 
Reply With Quote
 
John C. Bollinger
Guest
Posts: n/a
 
      10-22-2003
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
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-22-2003
On Wed, 22 Oct 2003 11:46:04 -0700, "Dale Packwood"
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      10-22-2003
Roedy Green <(E-Mail Removed)> scribbled the following
on comp.lang.java.programmer:
> On Wed, 22 Oct 2003 11:46:04 -0700, "Dale Packwood"
> <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Parthenogenetic procreation in humans will result in the founding of a new
religion."
- John Nordberg
 
Reply With Quote
 
Dale Packwood
Guest
Posts: n/a
 
      10-22-2003
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" <(E-Mail Removed)> wrote in message
news:bn6s5j$9pa$(E-Mail Removed)...
> Roedy Green <(E-Mail Removed)> scribbled the following
> on comp.lang.java.programmer:
> > On Wed, 22 Oct 2003 11:46:04 -0700, "Dale Packwood"
> > <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
> \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
> "Parthenogenetic procreation in humans will result in the founding of a

new
> religion."
> - John Nordberg



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
Help needed on this 857W config. Repost to be clearer what the problemsare and the help needed sparticle Cisco 3 08-30-2007 07:47 PM
Ideas needed & help needed! Ryan Macy Ruby 2 07-19-2006 08:04 PM
Microsoft small business server 2003 - help needed to understand what is needed to use it Dima Computer Support 5 10-20-2004 08:27 PM
newbie help with some help needed with a data array LeTubs Perl Misc 6 01-25-2004 03:13 AM



Advertisments