Ask Question
1 August, 12:40

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. 1 August, 16:26
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers