The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

newbie help....I don't know whats wrong with my program

Posted by Saguaro on February 21, 2002 at 12:05 AM

Its supposed to count the number of each letter in a string but all it returns is 0. I've been experimenting with it but I can't get it to work. Everything seems right. Can anyone help me with this? Thanks for your time
public class AlphaCounter
{
public static void main (String args[])
{
String enterLine, line;
int lineNum, numLines;
int numLetter;
int numVowel;
int i;
numLines=1;
int letterAp=0;

System.out.println("Enter lines of text. Enter an empty line to end.");
do {
line=SavitchIn.readLine();
if (!(line.equals("")))
numLines++;
} while(!(line.equals("")));
System.out.println("Number of lines: "+(numLines-1));
System.out.println("Letters not present: ");
numLetter=line.length();
line = line.toUpperCase();

for (char letter = 'A'; letter <= 'Z'; letter++)
{
for(i=0;i {
if (line.charAt(i)==letter)
letterAp++;
}

System.out.println(letter +" "+letterAp);
}
System.out.println("Number of letters: ");
System.out.println("Number of vowels: ");
}
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us