RiseAgainst7580 Posted March 12, 2009 Author Share Posted March 12, 2009 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 More sharing options...
Marsh Posted March 12, 2009 Share Posted March 12, 2009 isnt it if (x == y) Not sure about java but it would hav eto be that in c++. Link to comment Share on other sites More sharing options...
RiseAgainst7580 Posted March 12, 2009 Author Share Posted March 12, 2009 OMG ur awsome thank you Marsh Link to comment Share on other sites More sharing options...
RiseAgainst7580 Posted March 12, 2009 Author Share Posted March 12, 2009 my output is wrong though :( i didnt do it right or something..if you set the variables to the same # it prints out "x is smaller x is equal to y"its supposed to just say "x is equal to y"any hints? Link to comment Share on other sites More sharing options...
cheatking Posted March 12, 2009 Share Posted March 12, 2009 System.out.println("x is smaller"); { if (x = y) System.out.println("x is equal to y"); elseit executes the print then the if Link to comment Share on other sites More sharing options...
RiseAgainst7580 Posted March 12, 2009 Author Share Posted March 12, 2009 so how do i fix it?because i put the 2nd if right after the first if and then it said that the else was without an if Link to comment Share on other sites More sharing options...
Marsh Posted March 12, 2009 Share Posted March 12, 2009 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 More sharing options...
RiseAgainst7580 Posted March 12, 2009 Author Share Posted March 12, 2009 marsh i just put in what u said and the else that is after the ("x is smaller") makes it say " 'else' without 'if' " Link to comment Share on other sites More sharing options...
cheatking Posted March 12, 2009 Share Posted March 12, 2009 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 More sharing options...
Chakkra Posted March 12, 2009 Share Posted March 12, 2009 lol i dont even know wtf this is xD Link to comment Share on other sites More sharing options...
RiseAgainst7580 Posted March 12, 2009 Author Share Posted March 12, 2009 its for beginning computer programming class and i cant do the homework and make it actually work. by the way thank you to everyone who helped me and is helping me, my last homework post i got flamed on…. prolly because i wanted sum1 to write the program for me lol Link to comment Share on other sites More sharing options...
RiseAgainst7580 Posted March 12, 2009 Author Share Posted March 12, 2009 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 More sharing options...
RiseAgainst7580 Posted March 12, 2009 Author Share Posted March 12, 2009 this was just step 2 out of 5 steps on last weeks homework lol so ill prolly need more help in a little bit :)Thank You For Your Help :cheesy: Link to comment Share on other sites More sharing options...
RiseAgainst7580 Posted March 12, 2009 Author Share Posted March 12, 2009 uhhhhhhhh yeah idk how to do steps 3-5 and i dont wanna get flamed again or get in truble by any1 on here again lol Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now