Ask Question

Write code to print the location of any alphabetic character in the 2-character string passCode. Each alphabetic character detected should print a separate statement followed by a newline.

Ex: If passCode is "9a", output is:

Alphabetic at 1

import java. util. Scanner;

public class FindAlpha {

public static void main (String [] args) {

Scanner scnr = new Scanner (System. in);

String passCode;

passCode = scnr. next ();

/*Your solution goes here * /

}

}

+5
Answers (1)
  1. 25 November, 21:27
    0
    for (int i=0; i
    if ((passCode. charAt (i) > = 65 && passCode. charAt (i) = 97 && passCode. charAt (i) < = 122)) {

    System. out. println ("Alphabetic at " + i);

    }

    }

    Explanation:

    The rest of the code should be as above.

    In order to check if the character is alphabetic or not, we need to use ASCII table. Characters are represented as integers in the ASCII table. For example "a" equals 97, "A" equals 65.

    Then all we need to is to check if the character value in ASCII is in alphabetic ranges. If it is, print the index of the character.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write code to print the location of any alphabetic character in the 2-character string passCode. Each alphabetic character detected should ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers