How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • Go back-and-forth until satisfied
    Rate the answer you receive.
Ask LogicPro Your Own Question
LogicPro
LogicPro, Computer Software Engineer
Category: Programming
Satisfied Customers: 30964
Experience:  Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
29751445
Type Your Programming Question Here...
LogicPro is online now

Please complete task 6.

This answer was rated:

Please complete task 6.

Hi

public String andTheWinnerIs(String names[ ]) {
if(names==null || names.length==0)return null;
java.util.Random ran = new java.util.Random();
int i = ran.nextInt(names.length);
return names[ i ];
}

Thanks

Customer: replied 8 days ago.
is there any way of doing this without the pipe operation at all?

public String andTheWinnerIs(String names[ ]) {
if(names==null )return null;
if( names.length==0)return null;
java.util.Random ran = new java.util.Random();
int i = ran.nextInt(names.length);
return names[ i ];
}

Customer: replied 8 days ago.
thank you, ***** ***** complicated one could you please add // notes

public String andTheWinnerIs(String names[ ]) {

//if name null, return null
if(names==null )return null;

//if name blank, return null
if( names.length==0)return null;

//random object
java.util.Random ran = new java.util.Random();

//get a random number
int i = ran.nextInt(names.length);

//return name
return names[ i ];
}

LogicPro and 2 other Programming Specialists are ready to help you