Solved

if else if else if    using ? :

Posted on 2011-03-12
4
287 Views
Last Modified: 2012-06-21
hi guys

i have miltiple if else

like
if (user = manager)
{
user.name = 'Manager'
}
else if(user == CEO)
{
user.name = 'CEO'
}
else if(user == CLERK)
{
user.name = 'CLERK'
}

can i represent multiple If else conditions using ? :
for example

user == manager ? user.setName(MANAGER)  :  stuck here

any help appreciated

thakhs

0
Comment
Question by:royjayd
  • 3
4 Comments
 
LVL 18

Accepted Solution

by:
Raheman M. Abdul earned 400 total points
ID: 35117508
user==manager ? user.setName(MANAGER) : (  (user == CEO) ?  ( user.setName('CEO') ): (  (user == CLERK) ?  (user.setName('CLERK')) : (   )   )     )
0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 35117527
SAME AS

user==manager ? user.setName(MANAGER) :  (user == CEO) ?   user.setName('CEO') :   (user == CLERK) ?  user.setName('CLERK') : ()
0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 35117536
user==manager ? user.setName("MANAGER") :  (user == CEO) ?   user.setName("CEO") :   (user == CLERK) ?  user.setName("CLERK") : ()
0
 
LVL 26

Expert Comment

by:dpearson
ID: 35117940
If you're doing this sort of nest ternary operator here's a way to lay it out so people can read it.  Also you can assign the result to a variable and then use that in a single method call - so there's less code to change if you rename "user.setName".
 
String name = 
   (user == manager) ? "MANAGER"
   : (user == CEO) ? "CEO"
     : (user == CLERK) ? "CLERK"
       : "" ;

user.setName(name) ;

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now