Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 5th, 2005, 10:03 AM   #1
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Comparing Numbers

import java.awt.*;
import hsa.Console;
public class comparism
{
    static Console c = new Console ();
    static public void main (String[] args)
    {
        int a, b;
        c.clear ();
        do
        {
            c.print ("A = ? ");
            a = c.readInt ();
            c.print ("B = ? ");
            b = c.readInt ();
            if (a > b)
            {
                c.println (a + " is geater than " + b);
            }
            else
                if (a == b)
                {
                    c.println (a + " equals to " + b);
                }
                else
                    if (a < b)
                    {
                        c.println (a + " is less that " + b);
                    }
                    else

                        if (a == -999)
                        {
                            break;
                        }
        }
        while (a > b && a == b && a < b || a != -999);
    }
}

I want my program to end when i enter the number -999. Can you tell me what i'm doing wrong? i don't wanna change and of the following:

import java.awt.*;
import hsa.Console;
public class comparism
{
    static Console c = new Console ();
    static public void main (String[] args)
    {

can someone help me?
Dark Flare Knight is offline   Reply With Quote
Old Apr 5th, 2005, 10:15 AM   #2
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
Mmm.. in the while put just a!=-999. like this: while(a!=-999).
Also, the last if .. i don't think it's necesary after that.
__________________
Don't take life too seriously, it's not permanent !
xavier is online now   Reply With Quote
Old Apr 5th, 2005, 10:20 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
a > b && a == b && a < b

that will always evaluate to false,

if a <b then a !> b

if a == b etc etc etc so that statement is not required, just is

while(a != -999)

and yes the last if else is not required :/ just you had that odd thing in your while loop.



import java.awt.*;
import hsa.Console;
public class comparism
{
    static Console c = new Console ();
    static public void main (String[] args)
    {
        int a, b;
        c.clear ();
        do
        {
            c.print ("A = ? ");
            a = c.readInt ();
            c.print ("B = ? ");
            b = c.readInt ();
            if (a > b)
            {
                c.println (a + " is geater than " + b);
            }
            else if (a == b){
                    c.println (a + " equals to " + b);
            }
            else if (a < b){
                    c.println (a + " is less that " + b);
            }
       }
        while (a != -999);
    }
}
Berto is offline   Reply With Quote
Old Apr 5th, 2005, 10:29 AM   #4
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
or, if you want to exit faster, put if(a==-999)break; - before if(a>b)
__________________
Don't take life too seriously, it's not permanent !
xavier is online now   Reply With Quote
Old Apr 5th, 2005, 7:19 PM   #5
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Thanks yo i got it.
Dark Flare Knight is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC