Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

get random word 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

java random word from list

private static String[] names = { "Terminator", "Slicer","Ninja", "cow", "Robot", "littlegirl" };
name = names[(int) (Math.random() * names.length)];
System.out.println(name);
Comment

PREVIOUS NEXT
Code Example
Java :: random word java 
Java :: try catch out of bounds exception java 
Java :: int to enum java 
Java :: how to make an int into a string java 
Java :: java find longest string in list 
Java :: sum of arraylist java 8 
Java :: how to declare array java 
Java :: print * pattern in java 
Java :: how to find the largest number in a 2d array java 
Java :: How to perform breadth first search through a binary tree, in Java? 
Java :: turn java code to .exe 
Java :: war file vs jar file 
Java :: how to add elements in array in java using for loop 
Java :: how to enable cors request on springboot application 
Java :: set visible gui java 
Java :: use findviewbyid in fragment 
Java :: java change text on click 
Java :: java delete directory with files 
Java :: valueof vs tostring 
Java :: vscode java.home path 
Java :: check whether a double is not a number in java 
Java :: replace last char in string java 
Java :: string replace java 
Java :: if number is negative java 
Java :: from string to date 
Java :: intent flag clear task 
Java :: keytool error: java.io.FileNotFoundException: c:UsersUSER_NAMEupload-keystore.jks (The system cannot find the path specified) 
Java :: java install in fedora 
Java :: java empty array 
Java :: responseentity spring boot 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =