Advertisement
Guest User

cekSandi

a guest
Nov 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class cekSandi {
  4.     static String sandi="";
  5.     static int counterHuruf = 0;
  6.     static int counterAngka = 0;
  7.     static int counterSimbol = 0;
  8.     public static void cekIsi () {
  9.         for (int i = 0; i < sandi.length(); i++) {
  10.             char temp = sandi.charAt(i);
  11.             if (temp >= 'a' && temp <= 'z' || temp >= 'A' && temp <= 'Z') {
  12.                 counterHuruf++;
  13.             } else if (temp >= '0' && temp <='9'){
  14.                 counterAngka++;
  15.             }else counterSimbol++;
  16.         }
  17.     }
  18.     public static void cekValid(){
  19.         if (counterAngka+counterHuruf >=8 && counterAngka >=2 && counterSimbol==0){
  20.             System.out.println("Valid Password");
  21.         } else System.out.println("Invalid Password");
  22.     }
  23.  
  24.     public static void main(String[] args) {
  25.         Scanner in = new Scanner(System.in);
  26.         System.out.println("Syarat Password :");
  27.         System.out.println("1. Password Harus Memiliki Panjang 8 Karakter");
  28.         System.out.println("2. Password Hanya Berupa Huruf dan Angka");
  29.         System.out.println("3. Password Harus Memiliki Setidaknya 2 Angka");
  30.         System.out.print("Masukkan Password : ");
  31.         sandi=in.next();
  32.         cekIsi();
  33.         cekValid();
  34. //        System.out.println(counterHuruf);
  35. //        System.out.println(counterAngka);
  36. //        System.out.println(counterSimbol);
  37.  
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement