Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Can any1 explain what im doing wrong in my homework?


RiseAgainst7580
 Share

Recommended Posts

i put in red where it doesnt work… i use bluej.. it says "incompatible types-found int but expected boolean"
please help me out because ive been working on this for like a week trying to get it right and its already past due

/**
* Compare class compares 2 ints
*
* Joshua Seavey
* March 3, 2009
*/
public class Compare
{
  private int x, y;

  /**
    * Constructor for objects of class Compare
    */
  public Compare()
  {
      x = 0;
      y = 0;
    }

    /**
    * Easily change x and y
    *
    * @param  a  to set x
    * @param  b  to set y
    */
    public void set(int a, int b)
    {
        x = a;
        y = b;
    }

    /**
    * An example of an if statement
    *
    */
    public void compare()
    {
        if (x > y)
          System.out.println("x is greater");
        else
          System.out.println("x is smaller");
            {
                if (x = y)          System.out.println("x is equal to y");
        else
          System.out.println("x is smaller");
            }
        }
}
Link to comment
Share on other sites

if (x > y)
          System.out.println("x is greater");
        else
          System.out.println("x is smaller");
            else
                if (x = y)          System.out.println("x is equal to y");
        else
          System.out.println("x is smaller");

I cant test it without a java compiler. But i think you needed a else instead of a bracket.
Link to comment
Share on other sites

f (x > y)
          System.out.println("x is greater");
        else <- Cant that be elsif (x < y) or something?
          System.out.println("x is smaller");
            else
                if (x = y)          System.out.println("x is equal to y");
        else
          System.out.println("x is smaller");
Link to comment
Share on other sites

yay i fixed it :)
/**
* Compare class compares 2 ints
*
* Joshua Seavey
* March 3, 2009
*/
public class Compare
{
  private int x, y;

  /**
    * Constructor for objects of class Compare
    */
  public Compare()
  {
      x = 0;
      y = 0;
    }

    /**
    * Easily change x and y
    *
    * @param  a  to set x
    * @param  b  to set y
    */
    public void set(int a, int b)
    {
        x = a;
        y = b;
    }

    /**
    * An example of an if statement
    *
    */
    public void compare()
    {
        if (x > y)
          System.out.println("x is greater");
          {
            if (x == y)
              System.out.println("x is equal to y");
            else
              System.out.println("x is smaller");
            }
        }
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...