Recap - Validation Function
Part of the Fundamentals section of Coddy's Java journey — lesson 56 of 73.
Challenge
EasyWrite a method named is_valid that gets two strings arguments, username and password.
The method will return true if the username and password are valid in the system, otherwise false.
Our system contains only two valid usernames - "admin" and "user".
The valid password for username "user" is "qweasd".
For username "admin" any password is valid!
Try it yourself
import java.util.Scanner;
public class Main {
public static boolean is_valid(String username, String password) {
// Write your code below
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String user = scanner.nextLine();
String pass = scanner.nextLine();
boolean res = is_valid(user, pass);
System.out.println(res);
}
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison10Methods (Functions)
Declaring MethodsMethod ParametersReturn TypesMethod OverloadingRecap - Sigma FunctionRecap - Validation FunctionVoid Methods5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 43Variables Part 2
ConstantsNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementTernary OperatorRecap - If ElseNested If - Else