Java - Write code to get Random Password in digits

Requirements

Write code to get Random Password in digits

Demo

//package com.book2s;

import java.util.Random;

public class Main {
    public static String getRandomPass(Integer length) {
        Random randGen = new Random();
        char[] numbersAndLetters = ("0123456789").toCharArray();
        char[] randBuffer = new char[length];
        for (Integer i = 0; i < randBuffer.length; i++) {
            randBuffer[i] = numbersAndLetters[randGen.nextInt(10)];
        }//  ww  w  .ja v  a  2  s  .c  o  m
        return new String(randBuffer);
    }
}

Related Exercise