//This is perfectly working code. in this code whenever the input requirement( l
ID: 3653077 • Letter: #
Question
//This is perfectly working code. in this code whenever the input requirement( lenght not less than 6 and not more than 10 character with at least one ditgit and letter) // does not satisfy, i want to display the same user input saying put the correct format until user puts correct format.and only then i want to display re-enter password //match dialog box.// import java.util.*; class Password { public static void main(String[] args) { Scanner input = new Scanner(System.in); String goodPassword =""; String reEnter = ""; int check = 0; Password p = new Password(); System.out.println("Please select your password"); String password = input.next(); while(check == 0){ if((password.length() > 6)&&(password.length() < 10)){ if(p.oneNumoneLet(password)==true) { goodPassword = password; check = 1; } } else{ System.out.println("Please enter the correct format"); password = input.next(); } } if((password.length() > 6)&&(password.length() < 10)){ System.out.println("Please enter the re-enter password"); reEnter = input.next(); } while(!(reEnter.equals(goodPassword))){ System.out.println("Please re-enter your password"); reEnter= input.next(); { System.out.println("Thanks for entering your password"); } } } public boolean oneNumoneLet(String s) { int numCount = 0; int letCount = 0; for(int i = 0; i < s.length(); i++) { char c = s.charAt(i); if(Character.isDigit(c)){ numCount =+ 1; } if((Character.isLetter(c))){ letCount =+ 1; } } if((numCount > 0) && (letCount > 0)) { return true; } else{ return false; } } }Explanation / Answer
import java.util.*; class Password { public static void main(String[] args) { Scanner input = new Scanner(System.in); String goodPassword = ""; String reEnter = ""; Password p = new Password(); String password; do { System.out.println("Please select your password"); password = input.next(); if ((password.length() >= 6) && (password.length() 10 || p.oneNumoneLet(password) == false); if ((password.length() > 6) && (password.length() < 10)) { System.out.println("Please enter the Re-Enter password"); reEnter = input.next(); } while (!(reEnter.equals(goodPassword))) { System.out.println("Please re-enter your password"); reEnter = input.next(); { System.out.println("Thanks for entering your password"); } } } public boolean oneNumoneLet(String s) { int numCount = 0; int letCount = 0; for (int i = 0; i 0) && (letCount > 0)) { return true; } else { return false; } } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.