Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: in1To10 Date: Sat, 09 Aug 2014 15:58:08 -0400 Organization: A noiseless patient Spider Lines: 50 Message-ID: References: <0c8de66a-429a-4697-b575-35f37a7b6882@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 9 Aug 2014 19:58:30 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="b896cb427f8c4d19d14880347aa9d6ce"; logging-data="4273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gX/GJzt5V8/g3Y9UkNJLwe59hEbeuo94=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.7.0 In-Reply-To: <0c8de66a-429a-4697-b575-35f37a7b6882@googlegroups.com> Cancel-Lock: sha1:NxtUSC3HqddjhWUnwzjVRlmrYNU= Xref: csiph.com comp.lang.java.programmer:29598 On 08/09/2014 03:12 PM, cdalten@gmail.com wrote: > from the url > > http://codingbat.com/prob/p137365 > > The problem states: "Given a number n, return true if n is in the range 1..10, inclusive. Unless "outsideMode" is true, in which case return true if the number is less or equal to 1, or greater or equal to 10." > > Here is what I came up with... > > public class In1to10 { > static boolean in1To10(int n, boolean outsideMode) { > > if (outsideMode == false){ > if (n >= 1 && n <=10) { > return true; > } > } else if (outsideMode == true){ > if (n <=1 || n >=10) { > return true; > } > } > > return false; > } > public static void main(String[] args) { > System.out.println(in1To10(5, false)); //true > System.out.println(in1To10(11, false)); //false > System.out.println(in1To10(11, true)); //true > }//end main > } > > > Now upon googling the solutions, I saw some people use > if(outsideMode == false) > if(outsideMode == true) > > instead of using if(outsideMode == false)/else(outsideMode == true). > > Would both catch all the cases? If not, which one would? The Java Tutorial explains quite well the difference between if-then and if-then-else statements. Also what happens when a branching statement is encountered. > > Chad >