Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

print random from list java

import java.util.Random;

public class Selection
{    
  	public static void main(String[] args)    
    {       
        Random rand = new Random(); 
      	String[] animals = {"Dog", "Cat", "Fish", "Turtle", "Penguin"}; // array of animals
      	System.out.println("Console picked " + animals[rand.nextInt(animals.length)]); // prints the random animal selected from array
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: get random word from array java 
Java :: What is a point class in java? 
Java :: capitalize each word in string java 
Java :: java 11 download 64 bit 
Java :: java settimeout 
Java :: java get classname 
Java :: java array declaration 
Java :: java string remove more than one space 
Java :: converting excel to csv in java 
Java :: copy arraylist java 
Java :: java collection to list 
Java :: object to string in java 
Java :: Error inflating class ImageView 
Java :: Spring boot fix cors problem 
Java :: android studio go to another activity kotlin 
Java :: how to get width android 
Java :: android BottomSheetDialogFragment not opening fully on landscape 
Java :: java print variable type 
Java :: hashmap iteration 
Java :: java convert float to int 
Java :: java how to check string is number 
Java :: java loop array backwards 
Java :: sqlexception 
Java :: java File Separator 
Java :: linux command to see all the java version installed 
Java :: replace substring at index java 
Java :: caused by: java.lang.noclassdeffounderror: org/springframework/boot/configurationprocessor/json/jsonexception 
Java :: java create map 
Java :: reentrantlock java 
Java :: java responseentity 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =