/**
* This program prints usernames
* Author: Peter.T
* created: 9/12/2017
*/
import java.util.*;
public class Username {
public static void main(String[] args) {
int spot;
String full_name;
String grad_year;
String last_name;
String first_name;
String middle_name;
Scanner scan = new Scanner(System.in);
System.out.println("please enter your full name. (with space)");
full_name = scan.nextLine();
System.out.println("please enter your graduation year.");
grad_year = scan.nextLine();
spot = full_name.indexOf(" "); //finds first space
first_name = full_name.substring(0,spot);
full_name = full_name.substring(spot+1);
spot = full_name.indexOf(" "); //finds second space
middle_name = full_name.substring(0,spot);
last_name = full_name.substring(spot+1);
if(last_name.length() > 3){
if(middle_name.length() < 0){
System.out.println(last_name.substring(0,4)+middle_name.substring(0,1)+first_name.substring(0,1)+grad_year.substring(2));
}
else{
System.out.println(last_name.substring(0,4)+first_name.substring(0,1)+grad_year.substring(2));
}
}
else{
if(middle_name.length() < 0){
System.out.println(last_name.substring(0)+middle_name.substring(0,1)+first_name.substring(0,1)+grad_year.substring(2));
}
else{
System.out.println(last_name.substring(0)+first_name.substring(0,1)+grad_year.substring(2));
}
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.