Advertisement
kamandos

HW5

Jun 26th, 2022
1,027
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.date;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.        
  7.         Scanner scanner = new Scanner(System.in);
  8.         String str = scanner.nextLine();
  9.         char c[] = str.toCharArray();
  10.         System.out.println(validatePassword(c));
  11.     }
  12.     private static String validatePassword(char c[]) {
  13.         int flag = 0;
  14.         if(c.length < 6 || c.length > 20){
  15.             return "Invalid";
  16.         }
  17.         for(int i = 0 ; i < c.length ; i++){
  18.             if(c[i] == '@' || c[i] == '#' || c[i] == '$'|| c[i] == '0' || c[i] == '1' || c[i] == '2' || c[i] == '3' || c[i] == '4' || c[i] == '5' || c[i] == '6'|| c[i] == '7'|| c[i] == '8'|| c[i] == '9'){
  19.                 flag = 0;
  20.                 break;
  21.             }
  22.             flag = 1;
  23.             if(flag == 1){
  24.                 return "Invalid";
  25.             }
  26.         }
  27.         return "Valid";
  28.     }
  29. }
Advertisement
RAW Paste Data Copied
Advertisement