-1

I got it working but it is also counting the spaces between the words that are being typed. All i care is for the letters to be count and not the spaces. How or what can i do to change this? where am i messing up or missed something

import java.util.Scanner;

public class LetterCount
{
public static void main (String[] args)
{

    System.out.println("Type something ");
    Scanner n = new Scanner (System.in);
    String s = "";
    s = n.nextLine();
    char []c = s.toCharArray();
    int sz = c.length;
    int i =0, j=0, counter=0;

    for (i=0; i<sz; i++){
        counter =0;

            for(j=0; j<sz; j++)
            {

                if (j< i&& c[i] == c[j])
                {
                    break;
                }   

                if (c[j] == c[i])
                {
                    counter++;
                }

                if (j==sz-1)
                {
                    System.out.println("the character "+c[i]+" is present "+counter+" times");
                }
            }
    }


}

}

Neguido
  • 235
  • 2
  • 13
Noobie
  • 1
  • 1
  • 1
    Please try something and show us, before asking. – M. Page Nov 23 '14 at 19:49
  • import java.util.Scanner; public class LetterCount { public static void main (String[] args) { System.out.println("Type something "); Scanner n = new Scanner (System.in); String s = ""; s = n.nextLane(); // is telling cannot find symbol char []c = s.toCharArray(); int sz = c.length; int i =0, j=0, counter=0; for (i=0; i – Noobie Nov 23 '14 at 20:30

1 Answers1

0

What you'd want to do is remove the whitespace from the string before you count the letters;

Removing whitespace from strings in Java

Community
  • 1
  • 1
Neguido
  • 235
  • 2
  • 13