I'm having an extremely frustrating time trying to get the bug out of one of my programs. Basically my program takes in a string, and reads how many times each keyboard character occurs in the string, and then displays it.
The main loop I'm running which does the character reading, does not run through, even though the conditions are being met.
Do you have any idea what might be wrong?
import java.util.Scanner;
public class mainClass {
public static void main (String[] args){
Scanner myScanner = new Scanner(System.in);
System.out.println("Please enter array");
String inputString = myScanner.nextLine(); //input array entered
myScanner.close();
char[] charTypes = {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,`,~,!,@,#,$,%,^,&,*,(,),-,_,=,+,[,{,],},;,:};
char[] charArray = new char[inputString.length()];
for (int i =0; i<=inputString.length()-1;i++){ //conversion of string to character array
charArray[i]= inputString.charAt(i);
System.out.print(" "+ charArray[i] +" ");
}
int i1=0;
int i2=0;
int charCounter[] = new int[84]; //This array holds the amount of times each corresponding character occurs in a string
while (i1<=charArray.length-1){
if(charArray[i1]==charTypes[i2] && i22<83 && i1<charArray.length-1){
charCounter[i22]++;
i1++;
i22=0;
}else if(charArray[i1] != charTypes[i2] && i22<83 && i1<charArray.length-1){
i22++;
}else{System.out.println("Not even running through the if's");//introduced as as tests to see if the conditions of the two if statements were being met}
}
for(int i = 0; i<=91;i++){ // prints out how many times each character occurs
System.out.println(charTypes[i]+" : "+ charCounter[i]);
}
}
}