Random 1-5

    0

    4

    This code defines a class named Main and includes a main() method. Inside the main() method, the code defines a static variable named random and instantiates an instance of Random. Next, the code sets the value of the static variable x to be the result of a call to the nextInt() method of Random. The output of this code will be 6.

    package Davd;
    import java.util.Random;
    
    public class Main {
      public static void main(String[] args) {
    
      Random random = new Random();
      int x = random.nextInt(5)+1;
      System.out.print(x);
      }
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.