Results 1 to 8 of 8
Thread: Switch Case statement
- 01-26-2011, 03:10 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 40
- Rep Power
- 0
Switch Case statement
Can I have a Switch case statement inside another? For ex.
Java Code:switch(variableOne){ case 1: blah blah blah blah; blah blah blah blah; switch (variableTwo){ case 1: blah blah blah blah; blah blah blah blah; break; case 2: blah blah blah blah; blah blah blah blah; break; } break; case 2: blah blah blah blah; blah blah blah blah; switch (variableThree){ case 1: blah blah blah blah; blah blah blah blah; break; case 2: blah blah blah blah; blah blah blah blah; break; } break default: System.out.println("Error"); }
- 01-26-2011, 03:18 AM #2
Senior Member
- Join Date
- Jan 2011
- Location
- Bangalore, India
- Posts
- 102
- Rep Power
- 0
of course. Why can't you
Try this same code. It'll work perfectly fine
- 01-26-2011, 12:36 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 40
- Rep Power
- 0
Well when i use
I'm getting duplicate case errors???Java Code:System.out.printf("%s\n%s\n%s\n%s\n%s\n%s\n", "1. Circle", "2. Rectangle", "3.Square", "4. Triangle", "5. Cone", "Cylinder"); int selectionOne = input.nextInt(); switch(selectionOne) { case 1: System.out.println("What is the Radius of the Circle? "); int R1 = input.nextInt(); System.out.println("What is the Diameter of the Circle? "); int D1 = input.nextInt(); Circle C1 = new Circle(D1, R1); System.out.println("1 for Area, and 2 for Perimeter: "); int asking = input.nextInt(); Switch(asking){ case 1: System.out.println(C1.getArea()); break; case 2: System.out.println(C1.getPerimeter()); break; default: System.out.println("System Error"); } }
- 01-26-2011, 12:49 PM #4
Senior Member
- Join Date
- Jan 2011
- Location
- Bangalore, India
- Posts
- 102
- Rep Power
- 0
I don't find anything wrong still.
Just to make sure I copied your code and compiled and ran. No problems, except that second switch is misspelled (S is in upper case).
- 01-26-2011, 02:30 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-27-2011, 08:37 PM #6
You spelled Switch with a capital S. Its lowercase.
- 02-15-2011, 08:03 AM #7
Member
- Join Date
- Nov 2010
- Posts
- 40
- Rep Power
- 0
Thanks a lot quad.... I can't believe I missed that lol very embarrassing.
- 02-15-2011, 01:18 PM #8
Similar Threads
-
switch case with integers and strings...
By JavaComplient in forum New To JavaReplies: 2Last Post: 10-21-2010, 06:52 AM -
if else changes to switch-case?
By noobinoo in forum New To JavaReplies: 1Last Post: 04-23-2010, 05:56 PM -
[SOLVED] Making Switch Case Insensitive?
By iPetey in forum New To JavaReplies: 6Last Post: 04-09-2009, 04:46 PM -
[SOLVED] Is it possible to have If in a switch case?
By sfe23 in forum New To JavaReplies: 2Last Post: 02-23-2009, 12:34 AM -
Switch Case and Key Events
By AndrewM16921 in forum New To JavaReplies: 4Last Post: 01-26-2009, 11:20 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks