Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class cekSandi {
- static String sandi="";
- static int counterHuruf = 0;
- static int counterAngka = 0;
- static int counterSimbol = 0;
- public static void cekIsi () {
- for (int i = 0; i < sandi.length(); i++) {
- char temp = sandi.charAt(i);
- if (temp >= 'a' && temp <= 'z' || temp >= 'A' && temp <= 'Z') {
- counterHuruf++;
- } else if (temp >= '0' && temp <='9'){
- counterAngka++;
- }else counterSimbol++;
- }
- }
- public static void cekValid(){
- if (counterAngka+counterHuruf >=8 && counterAngka >=2 && counterSimbol==0){
- System.out.println("Valid Password");
- } else System.out.println("Invalid Password");
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.println("Syarat Password :");
- System.out.println("1. Password Harus Memiliki Panjang 8 Karakter");
- System.out.println("2. Password Hanya Berupa Huruf dan Angka");
- System.out.println("3. Password Harus Memiliki Setidaknya 2 Angka");
- System.out.print("Masukkan Password : ");
- sandi=in.next();
- cekIsi();
- cekValid();
- // System.out.println(counterHuruf);
- // System.out.println(counterAngka);
- // System.out.println(counterSimbol);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement