import java.util.Scanner; public class FunWithStrings{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter a string: "); String txt = scan.nextLine(); int lcv = 0; // init lcv while(lcv < txt.length()) { // test lcv System.out.print("position: " + lcv); System.out.println(" char: " + txt.charAt(lcv)); lcv++; // update lcv } // Now, print the characters in reverse order. int cntAs = 0; lcv = txt.length() - 1; while (lcv >= 0) { char ch = txt.charAt(lcv); System.out.print(ch); if (ch == 'a' || ch == 'A') { cntAs++; } lcv--; } System.out.println(); System.out.println("There were " + cntAs + " as."); } //main }