Skip to content

Instantly share code, notes, and snippets.

@joeyv
Last active December 26, 2015 08:39
Show Gist options
  • Select an option

  • Save joeyv/7123579 to your computer and use it in GitHub Desktop.

Select an option

Save joeyv/7123579 to your computer and use it in GitHub Desktop.
Generates a username based off of the first letter of your name, the first 5 letters of your last name, and a random 2 digit number.
import java.util.*;
public class Usernames {
public static void main(String[] args) {
String first, last, username;
int randomNum;
// Scan in first and last name
Scanner scan = new Scanner(System.in);
first = scan.next();
last = scan.next();
// Create random number 10-99
// add 10 so the lowest number generated is 10
// randomize 90 numbers because 0 counts as a number
Random generator = new Random();
randomNum = generator.nextInt(90) + 10;
// Display custom username
username = first.charAt(0) + last.substring(0, 5) + randomNum;
System.out.println(username);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment