67 007
Assignments Done
99,2%
Successfully Done
In November 2018

Answer to Question #21331 in Java | JSP | JSF for shalenee

Question #21331
Write a simple java program that generates 10 non-duplicate random integers within the range from 0 to 20.
Expert's answer
public class main
{
staticint n=10;
staticint[] res=new int[n];

publicstatic void main(String[] args)
{
intcount=0;
Randomr=new Random();
inttmp;
while(count<n)
{
if(!isContains(tmp=r.nextInt(21)))
{
res[count]=tmp;
count++;
}
}

System.out.println(Arrays.toString(res));
}

privatestatic boolean isContains(int el)
{
for(int i = 0; i < res.length; i++)
{
if(el==res[i])
{
returntrue;
}
}

returnfalse;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions