Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main
- {
- public static void main(String [ ] args)
- {
- // System variables
- Scanner keyboard = new Scanner(System.in);
- // Normal variables
- String firstname = "";
- String surname = "";
- String password = "";
- String username = "";
- String email = "";
- String company = "";
- int passwordLength = 0;
- int amountNumbers = 0;
- // Getting nesseccary inputs
- System.out.print("Please enter first name : ");
- firstname = keyboard.nextLine();
- System.out.print("Please enter surname : ");
- surname = keyboard.nextLine();
- System.out.print("Please enter password : ");
- password = keyboard.nextLine();
- System.out.print("Please enter your company : ");
- company = keyboard.nextLine();
- username = firstname.toLowerCase() + "." + surname.toLowerCase();
- passwordLength = password.length();
- email = username + "@" + company + ".com";
- System.out.print("Please enter password : ");
- password = keyboard.nextLine();
- passwordLength = password.length();
- // Splits the password into an array and checks each one to see if it is a number or not.
- char[] passwordArray = password.split("");
- // Program iterates over all array elements at once
- for (char character : passwordArray)
- {
- if (Character.isDigit(character))
- {
- amountOfNumbers++;
- }
- else
- {
- return;
- }
- }
- // Checks if the password has at least 8 characters, and there is at least 2 numbers
- while (passwordLength < 8 || amountOfNumbers < 2) {
- if (passwordLength < 8)
- {
- System.out.println("Your password is not long enough.");
- } else {
- if(amountOfNumbers < 2) {
- System.out.println("You don't have enough numbers.");
- }
- }
- }
- // Prints out the nesseccary outputs in the right format.
- System.out.println("username is : " + username);
- System.out.println("Your password has " + passwordLength + " characters");
- System.out.println("Your email is : " + email);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement