import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner input = new Scanner(System.in);
System.out.println("Enter the password");
String password = input.nextLine().trim();
System.out.println(password + (isValidPassword(password) ? "is true" : "is false"));
}
public static boolean isValidPassword(String password){
return hasValidLength(password) && hasValidPrefix(password);
}
public static boolean hasValidLength(String password){
return number.length() >= 8 password.length() <= 16;
}
}
Witam
Jestem początkujący w Javi-e i mam takie zadanie do rozwiązania :
Some websites impose certain rules for passwords. Suppose the password rules for
a particular website are as follows:
• The password must have at least eight characters.
• The password must consist of only letters (either lowercase or uppercase) and
digits.
• The password must contain at least three digits.
• The sum of the ASCII code value (in decimal) of each letter in the password
must be at least 400.
A password is valid if it satisfies all of the above rules. Write each of the following
methods to check whether a string is a valid password.
(Note: In your solution, you must use the method headers specified below. Other
than writing these methods, there is no requirement to write any additional code.)
// Returns true if the password is valid
public static boolean isValidPassword(String password)
// Returns true if the password has at least 8 characters
public static boolean isValidLength(String password)
// Returns true if the password consists of only letters and
// digits
public static boolean consistsLettersDigits(String password)
// Returns the count of the number of digits in the password
public static int countDigits(String password)
// Returns the sum of the ASCII code value (in decimal) of
// each letter in the password
public static int sumLetters(String password)
Czy podążąm w dobrym kierunku czy przy hasValidLength mam zmienić na hasValidCharacter.
Na końcu zaś będzie for (int i = password.length()........ ?
Czy mam rację?
Chciałbym się poradzić jeszcze w jednej kwestii: mam jeszcze jedno zadanko z metodami:
Muszę napisać metodę aby znaleźć minimum wartości dwóch liczb całkowitych/czterech liczb i muszę użyć tych metod:
public static int min2(int n1, int n2)
public static int min4(int n1, int n2, int n3, int n4)
metoda min4 powinna odwoływać się do metody min2 kiedy znajdzie minimum czterech liczb.