Hi
I'm i beginner in java :$
and i have a problem .... with the code
they want from me to write a program that reads and prints the number of occurrence of each alphabetical letter in the string . the program should call a method to creat an array for the counters of the letters , and use another overloaded method that receives a character and updates the corresponding counter and finally call a third method to print the counts
this is my code and i just cant get it right ....!!
import java.util.*;
import java.lang.*;
public class Q2
{
public static void main (String args[])
{
Scanner console=new Scanner(System.in);
int []coun;
System.out.println("Enter the Sentence");
String str=console.nextLine();
coun=new int[str.length()];
str=str.toLowerCase();
int i=0;
while(i<str.length()){
char s=str.charAt(i);
int counter=0;
if(Character.isLetter(str.charAt(i)))
for(int j=0;j<str.length();j++){
char t=str.charAt(j);
if(Character.isLetter(str.charAt(j)))
if(t==s)
counter++;
i++;
System.out.print(t+"="+(counter)+",");
}}
counterr(counter,coun);// here there is a compile error that symbol : variable counter
}
public static void counterr (int counter,int[] coun)
{
for(int index=0;index<coun.length;index++)
coun[index]=counter;
}
}
and when i remove the method and leave only the main the run is like that
Enter the Sentence
java
j=1,a=1,v=1,a=1,
:(