DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  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

    > }
    >>> }

    >
    >>

    >



Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links