J
jcsencsits
I am trying to get this to print the number of J's there are in the
users input. and then ask if they want to try again. can someone help
me ecause it doesn't count all lettr J's
import java.util.Scanner;
class countletter
{
public static void main(String[] args) {
int numOfJ = 0;
int control = 1;
int i = 0;
String randomString = " ";
char charLetter;
do {
numOfJ = 0; //j,J
Scanner scan = new Scanner(System.in);
System.out.print("Enter a string: ");
randomString = scan.next();
for (int letter = 0; letter < randomString.length(); letter++) {
charLetter = randomString.charAt(letter);
if (charLetter == 'j' || charLetter == 'J') {
numOfJ++;
} }
System.out.println("\nNo. of 'J' / 'j' = " + numOfJ);
System.out.println(
"If you would like to run the program for another string
please enter 1.");
control = scan.nextInt();
}
while (control == 1);
}
}
users input. and then ask if they want to try again. can someone help
me ecause it doesn't count all lettr J's
import java.util.Scanner;
class countletter
{
public static void main(String[] args) {
int numOfJ = 0;
int control = 1;
int i = 0;
String randomString = " ";
char charLetter;
do {
numOfJ = 0; //j,J
Scanner scan = new Scanner(System.in);
System.out.print("Enter a string: ");
randomString = scan.next();
for (int letter = 0; letter < randomString.length(); letter++) {
charLetter = randomString.charAt(letter);
if (charLetter == 'j' || charLetter == 'J') {
numOfJ++;
} }
System.out.println("\nNo. of 'J' / 'j' = " + numOfJ);
System.out.println(
"If you would like to run the program for another string
please enter 1.");
control = scan.nextInt();
}
while (control == 1);
}
}