Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

public class Main {
    private static final String ALPHA_NUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static void main(String[] args) {
        GenerateRandomString grs = new GenerateRandomString();
        System.out.println(grs.getAlphaNumeric(10));
        System.out.println(grs.getAlphaNumeric(20));
    }

    public String getAlphaNumeric(int len) {
        StringBuffer sb = new StringBuffer(len);
        for (int i = 0; i < len; i++) {
            int ndx = (int) (Math.random() * ALPHA_NUM.length());
            sb.append(ALPHA_NUM.charAt(ndx));
        }
        return sb.toString();
    }
}