EA Username D

import java.util.*; public class Username{ public static void main (String [] args) { boolean again = true; while(again){ Scanner scan = new Scanner(System.in); System.out.println ("What is your full name?"); String fullName = scan.nextLine(); String fName = fullName.substring(0,1); int space1 = fullName.indexOf(" "); String mName = fullName.substring(space1 + 1,space1 + 2); int space2 = fullName.indexOf(" ", space1 + 1); String lName = fullName.substring(space2 + 1); if( space2 < 1 ){ lName = fullName.substring(space1 + 1,space1 + 5); } if(lName.length() > 1 ){ if(lName.length() >= 4){ lName = lName.substring(0,4); } if(lName.length() == 3){ lName = lName.substring(0,3); } if(lName.length() == 2){ lName = lName.substring(0,2); } if(lName.length() == 1){ lName = lName.substring(0,1); } }else{ System.out.println("Not an acceptable username"); } System.out.println("What year are you graduating?"); String grad = scan.nextLine(); grad = grad.substring(2,4); if( space2 < 1 ){ System.out.println ("Ea username is : " + lName + fName + grad); }else{ System.out.println ("Ea username is : " + lName + fName + mName + grad); } System.out.println(" Press 1 to do another username, 2 to cancel"); int another = scan.nextInt(); if (another == 1){ again = true; } if (another == 2){ again = false; } } } }

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.