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: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: Help writing a program using a switch statement Date: Sat, 11 Oct 2014 07:59:49 -0700 Organization: A noiseless patient Spider Lines: 60 Message-ID: References: <8dcbb682-a1c4-4e43-b506-093de204ae87@googlegroups.com> <54388fd2$0$292$14726298@news.sunsite.dk> <543933f5$0$301$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 11 Oct 2014 14:59:46 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="aba33539224e5c782fe0c4053f7756fd"; logging-data="22758"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dY/wPPoyR2vdVklEISHUU" User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1 In-Reply-To: <543933f5$0$301$14726298@news.sunsite.dk> Cancel-Lock: sha1:UNa6R7ZGbNlDjsShyly686YzfaU= Xref: csiph.com comp.lang.java.programmer:30076 On 10/11/2014 06:43, Arne Vajhøj wrote: > On 10/10/2014 11:27 PM, Knute Johnson wrote: >> On 10/10/2014 19:02, Arne Vajhøj wrote: >>> On 10/5/2014 8:18 PM, Knute Johnson wrote: >>>> On 10/5/2014 15:40, Abraar Ahmed wrote: >>>>> Write a program using switch statement to allow users to choose an >>>>> item of a menu. For example, the menu looks like the following. >>> >>>>> switch (1) { >>>>> case value: 1 >>>>> System.out.println ("Open is selected"); >>>>> break; >>>>> case value: 2 >>>>> System.out.println ("Close is selected"); >>>>> break; >>>>> case value: 3 >>>>> System.out.println ("Save is selected") >>>>> break; >>>>> System.out.println ("Exit is selected") >>>>> default: >>>>> values_not_caught_above; >>>>> >>>>> } >>> >>>> Since this is homework, you need to look at the Java Language >>>> Specification, chapter 14.11 Switch Statement. Everything you need to >>>> know is there. >>>> >>>> http://docs.oracle.com/javase/specs/jls/se8/html/index.html >>> >>> JLS is good for many things, but learning basic Java syntax is not >>> one if them. >>> >>> The Java tutorial would be a lot easier to learn from. >>> >>> http://docs.oracle.com/javase/tutorial/java/index.html >>> >>> http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html >> >> There are some good examples in the JLS for the switch statement though. > > It has 3 examples: > * some code that works in C/C++ but does not work in Java > * some code showing fall through > * some normal code > > Compare that to the tutorial that has 5 examples: > * some normal code > * some code showing how it would look like using if else if > * some code showing fall through > * some code showing multi labels > * some code showing switch on strings > > Arne OK I concede, you should have answered him not me. -- Knute Johnson