Generate random number between 1 to 10 in Java

By | August 9, 2020

How to generate random number between 1 to 10 in Java:

We can use nextInt() method of Random class to generate random number between 1 to 10 in java.

Output:

Note:

If we just use nextInt(10), then it will give a random number between 0 to 9. So if you don’t want 0 then you can use nextInt(10)+1 to get a random number between 1 to 10.

 

Recommended Posts:

How to remove last element from an ArrayList

Remove element from ArrayList

How to swap two numbers without using third variable in Java ***

How to capitalize each word in Java

Java interview questions

Generate random between 1 to 5 in Java

 

Note: If you like selenium99.com and want to contribute any articles, then please send your articles to techygeeks99@gmail.com. 

If you want to improve this article or find any mistake in the article, then please use comment box to share your feedback.

Links: TestNG

arrays tostring in java | selenium interview questions | binary search

 

 

 

 

 

Links: TestNG

Play & Win contest by Selenium99

Home 1

Leave a Reply

Your email address will not be published. Required fields are marked *