Re: Help - Loops-try this


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Re: Help - Loops-try this

  1. #1
    kuhan Guest

    Re: Help - Loops-try this


    "mazin" <mazin_ghafadgi@hotmail.com> wrote:
    >
    >"Andy" <andrew.constable@ntlworld.com> wrote:
    >>
    >>Can anyone help!
    >>
    >>I am trying to use a if else loop and it does not seem to work.
    >>What I am trying to do is create a class called maxNumber with all methods
    >>in for a test class which calls the maxNumber class to return the values.The
    >>code that I am having problems with is
    >>below.
    >>
    >> //Updates the maximum value to the value specified
    >> //if necessary - if the value is greater than the
    >> //current maxValue.
    >>
    >> public void setMaxValue(int value)
    >> {
    >> if (value > maxValue)
    >> {
    >> maxValue = value;
    >> }
    >> else
    >> {
    >> maxValue = maxValue;
    >> }
    >> }
    >>I want the maxValue to be updated by the value in the parameter only if

    >the
    >>value is above the current maxValue.
    >>Help!!
    >>
    >>Andy

    >
    >
    > try to use else if { it is more powerfull than using the esle on it own
    >}
    >
    >
    >
    > public void setMaxValue(int value)
    > {
    > if (value > maxValue)
    > {
    > maxValue = value;
    > }
    > else if ( value < maxvalue )
    > {
    > maxValue = maxValue;
    > }
    > }
    >
    >

    try this

    > public int setMaxValue(int value)
    >> {
    >> if (value > maxValue)
    >> {
    >> maxValue = value;
    >> return maxValue;

    }
    >> else
    >> {
    >> maxValue = maxValue;
    >> return maxValue

    }
    >> }


    >



  2. #2
    kuhan Guest

    Re: Help - Loops-try this


    >>

    >try this
    >
    >> public int setMaxValue(int value)
    >>> {
    >>> int maxValue=0;

    if (value > maxValue)
    >>> {
    >>> maxValue = value;
    >>> return maxValue;

    > }
    >>> else
    >>> {
    >>> maxValue = maxValue;
    >>> return maxValue

    > }
    >>> }

    >
    >>

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center