• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Use an array element as a case statement in switch

 
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Output of following code is Circle



İn my opinion array index starts with 0. And shapes[1]="Square". It will match with case "Square". Output must be Square. What is my wrong?
If i changed switch (shapes[1]) to switch (shapes[2]) the output will be "Square" and changed switch (shapes[1]) to switch (shapes[0]) the output will be "Triangle"



 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nil. Hatamova wrote:İn my opinion array index starts with 0. And shapes[1]="Square". It will match with case "Square". Output must be Square. What is my wrong?


Look very closely to the println statement of the case label "Square". Which String will be printed?
 
Nil. Hatamova
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh No Sorry
I hope i will not do the same in exam. I need to be more carefully
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nil. Hatamova wrote:Sorry
I hope i will not do the same in exam. I need to be more carefully


No need to apologize! We are all here to learn and most of the times you learn much more from mistakes (failure) than from success.

And it's much better to make such a mistake here than on the actual exam But you have indeed to be much more careful and pay close attention to details. That's one of the reasons why the exam is very hard (difficult): you have to be really focused and read every question and code snippet very carefully.
reply
    Bookmark Topic Watch Topic
  • New Topic