Create a Java program to demonstrate the use of an interface with private methods for validation
import java.util.Scanner; public class ValidationDemo implements Validator { public static void main(String[] args) { ValidationDemo validator = new ValidationDemo(); Scanner scanner = new Scanner(System.in); System.out.println("Enter a String to Validate : "); String input = scanner.nextLine(); if (validator.isValid(input)) { System.out.println("Input is Valid"); } else { System.out.println("Input is Not Valid"); } scanner.close(); } } interface Validator// Define an interface with private methods for validation { default boolean isValid(String input) { return validateLength(input) && validateContent(input); } private boolean validateLength(String input) { return input.length() >= 5; } private boolean validateContent(String input) { return input.matches(".*[a-zA-Z]+.*"); } }
Enter a String to Validate : Joes1234 Input is Valid
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions