Advertisement
Guest User

Untitled

a guest
Oct 10th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import java.util.*;
  2. public class Main
  3. {
  4. public static void main(String [ ] args)
  5. {
  6. // System variables
  7. Scanner keyboard = new Scanner(System.in);
  8.  
  9. // Normal variables
  10. String firstname = "";
  11. String surname = "";
  12. String password = "";
  13. String username = "";
  14. String email = "";
  15. String company = "";
  16.  
  17. int passwordLength = 0;
  18. int amountNumbers = 0;
  19.  
  20. // Getting nesseccary inputs
  21. System.out.print("Please enter first name : ");
  22. firstname = keyboard.nextLine();
  23. System.out.print("Please enter surname : ");
  24. surname = keyboard.nextLine();
  25. System.out.print("Please enter password : ");
  26. password = keyboard.nextLine();
  27. System.out.print("Please enter your company : ");
  28. company = keyboard.nextLine();
  29.  
  30. username = firstname.toLowerCase() + "." + surname.toLowerCase();
  31.  
  32. passwordLength = password.length();
  33.  
  34. email = username + "@" + company + ".com";
  35.  
  36.  
  37. System.out.print("Please enter password : ");
  38. password = keyboard.nextLine();
  39.  
  40. passwordLength = password.length();
  41.  
  42.  
  43. // Splits the password into an array and checks each one to see if it is a number or not.
  44.  
  45. char[] passwordArray = password.split("");
  46.  
  47. // Program iterates over all array elements at once
  48. for (char character : passwordArray)
  49. {
  50. if (Character.isDigit(character))
  51. {
  52. amountOfNumbers++;
  53. }
  54. else
  55. {
  56. return;
  57. }
  58. }
  59.  
  60. // Checks if the password has at least 8 characters, and there is at least 2 numbers
  61. while (passwordLength < 8 || amountOfNumbers < 2) {
  62. if (passwordLength < 8)
  63. {
  64. System.out.println("Your password is not long enough.");
  65. } else {
  66. if(amountOfNumbers < 2) {
  67. System.out.println("You don't have enough numbers.");
  68. }
  69. }
  70. }
  71.  
  72. // Prints out the nesseccary outputs in the right format.
  73. System.out.println("username is : " + username);
  74. System.out.println("Your password has " + passwordLength + " characters");
  75. System.out.println("Your email is : " + email);
  76.  
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement