Results 1 to 6 of 6
Thread: finding errors in if statements
- 03-29-2012, 11:21 PM #1
Member
- 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
- 03-29-2012, 11:44 PM #3
Member
- 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.
- 03-30-2012, 08:56 PM #4
Member
- 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.
- 03-30-2012, 09:40 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,420
- Blog Entries
- 7
- Rep Power
- 17
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)When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-30-2012, 10:36 PM #6
Member
- 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: 12-21-2011, 02:29 PM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
Out of bounds exception Errors (Trouble finding problem)
By sidd0123 in forum New To JavaReplies: 12Last Post: 05-06-2010, 10:54 AM -
Pleas help on finding errors
By McXxT in forum New To JavaReplies: 6Last Post: 04-02-2009, 08:42 AM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks