1

this piece of code about making a string password which is string.

import java.util.*;

public class Solution{

static int minimumNumber(int n, String password){    
   int arr[]=new int[n];
    String A[]=new String[4];
   String numbers = "0123456789";
   String lower_case = "abcdefghijklmnopqrstuvwxyz";
   String upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   String special_characters = "!@#$%^&*()-+";
    A[0]=numbers;
    A[1]=lower_case;
    A[2]=upper_case;
    A[3]=special_characters;
    for(int i=0;i<n;i++){
      for(int k=0;k<4;k++){
          for(int j=0;j<A[k].length();j++){
              if(password.charAt(i)==A[k].charAt(j)){
                  arr[i]=k;

                }
          }
     }
   }
    int ano[]=new int[4];
    ano[0]=0;
    ano[1]=1;
    ano[2]=2;
    ano[3]=3;
    for(int i=0;i<4;i++){
         int a=0;
        for(int j=0;j<n;j++){

            if(ano[i]==arr[j]){
                break;
            }
            else if(arr[i]!=ano[j]){
                a++;
            }
        }
        if(a==n){
            password=password+A[i];
        }
    }
    int n1=6-password.length();
    if(n1>=2){
        for(int i=0;i<n1;i++){
            password=password+A[0].charAt(i);
        }
    }
    int w=password.length()-n;
    return w;

}

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    String password = in.next();
    int answer = minimumNumber(n, password);
    System.out.println(answer);
    in.close();
}

}

01)it gives run time error Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3 at Solution.minimumNumber(Solution.java:42) at Solution.main(Solution.java:65)

  • See also: [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). – Turing85 May 01 '18 at 16:26

0 Answers0