Results 1 to 6 of 6
Thread: finding errors in if statements
 03292012, 11:21 PM #1Member
 Join Date
 Mar 2012
 Posts
 55
 Rep Power
 0
finding errors in if statements
Find the errors in the following if statements.
a. if (x && y == 0) { x = 1; y = 1; }
b. if (1 <= x <= 10)
System.out.println(x);
c. if (!s.equals("nickels")  !s.equals("pennies")
 !s.equals("dimes")  !s.equals("quarters"))
System.out.print("Input error!");
d. if (input.equalsIgnoreCase("N")  "NO")
return;
To some advanced users, this may seem simple. However for me it;s hard to pick out! Does anyone want to take a wack at it? Thanks!

Re: finding errors in if statements
 03292012, 11:44 PM #3Member
 Join Date
 Mar 2012
 Posts
 55
 Rep Power
 0
Re: finding errors in if statements
Ok, not sure if this is right. I think in b.) it should be changed to f (1 <= x && x <= 10) otherwise it wont work.
In c.) ! means not, so I dont understand what !s.equals("dimes") etc means? that looks like it would translate to not s equals.
a.) doesnt make much sense to me either because what i'm getting from it is : if x and y have a value of 0, x =1 and y=1.
 03302012, 08:56 PM #4Member
 Join Date
 Mar 2012
 Posts
 55
 Rep Power
 0
Re: finding errors in if statements
Can someone tell me if my answer (or part of the answer) if true at all? Thanks.
 03302012, 09:40 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
Re: finding errors in if statements
c) is also incorrect but for an entirely different reason (the others don't even syntactically make sense); suppose you want to test something against A and B; suppose that something is C; of course it isn't equals to A or B; but now suppose the something if A; it is definitely equal to A but it isn't equal to B so the or test () is still true: A isn't equals to A or B.
kind regards,
Jos (or not Jos)Build a wall around Donald Trump; I'll pay for it.
 03302012, 10:36 PM #6Member
 Join Date
 Mar 2012
 Posts
 55
 Rep Power
 0
Similar Threads

Finding Errors in JSP page with PMD
By srinivasmallabathula in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 12212011, 02:29 PM 
First Java ProgramCompile Errors (errors are posted)simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01042011, 12:36 AM 
Out of bounds exception Errors (Trouble finding problem)
By sidd0123 in forum New To JavaReplies: 12Last Post: 05062010, 10:54 AM 
Pleas help on finding errors
By McXxT in forum New To JavaReplies: 6Last Post: 04022009, 08:42 AM 
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03082009, 01:51 AM
Bookmarks