aznkidlee
Mar 03, 2004, 07:15 PM
Does anybody see anything wrong with this code?
public class ACSLMAN
{
public static void Keyboard (String input)
{
Keyboard kb = new Keyboard ();
System.out.print (">");
input = kb.readString();
System.out.println(input);
}
public static void check (String input)
{
// char [] letters = new char [25];
// int [] counter = new int [25];
int countA=0;
int countB=0;
int index=0;
while (index < input.length())
{
if (input.charAt(index) == 'a')
{
countA = countA + 1;
}
if (input.charAt(index) == 'b')
{
countB = countB + 1;
}
index=index +1;
}
System.out.println (countA);
System.out.println (countB);
}
public static void main ()
{
String input ="";
int counter = 0;
while (counter < 2)
{
Keyboard(input);
check(input);
counter++;
}
}
}
The program is not done yet, but basically I want this program to count up the number of letters of the users input.
The output of this program is incorrect. I enter aa and it gives me 0. It should be 2. I am not sure whats wrong with this so I am wondering if anybody can help me?
public class ACSLMAN
{
public static void Keyboard (String input)
{
Keyboard kb = new Keyboard ();
System.out.print (">");
input = kb.readString();
System.out.println(input);
}
public static void check (String input)
{
// char [] letters = new char [25];
// int [] counter = new int [25];
int countA=0;
int countB=0;
int index=0;
while (index < input.length())
{
if (input.charAt(index) == 'a')
{
countA = countA + 1;
}
if (input.charAt(index) == 'b')
{
countB = countB + 1;
}
index=index +1;
}
System.out.println (countA);
System.out.println (countB);
}
public static void main ()
{
String input ="";
int counter = 0;
while (counter < 2)
{
Keyboard(input);
check(input);
counter++;
}
}
}
The program is not done yet, but basically I want this program to count up the number of letters of the users input.
The output of this program is incorrect. I enter aa and it gives me 0. It should be 2. I am not sure whats wrong with this so I am wondering if anybody can help me?
