/*
Solution to Problem 6 of Practice Problem Set-1.
Aditya Mathur. January 27, 2019
 */

import java.util.Scanner;
public class CharExtraction {

    public static void main(String[] args) {
        String aString; //Arbitrary string
        int x, y; //Left and right markers for characters in a string


        Scanner s = new Scanner(System.in); // For keyboard input

        System.out.print("Enter any string: ");
        String ss = s.nextLine();
        if (ss.length()==0){
            System.out.println("You entered an empty string. Bye!");
            System.exit(0);
        }

        // Get character markers..
        System.out.print("Enter x: ");
        x = s.nextInt();
        System.out.print("Enter y: ");
        y = s.nextInt();
        int len=ss.length();
        if ((x<0 || x>=len)|| (y<0 || y>=len)){
            System.out.println("Sorry, x or y does not fall within the string");
            System.exit(0);
        }
        char charAtx = ss.charAt(x);
        char charAty = ss.charAt(y);
      //  String combine=Character.toString(charAtx)+Character.toString(charAty);
        System.out.printf( "Char at %d %c\n", x, charAtx);
        System.out.printf( "Char at %d %c\n", y, charAty);
        if (charAtx==charAty){
            System.out.println("Yes, characters are same.");
        }
        else{
            System.out.println("No, characters are not same.");
        }
    }// End of main
}//End of class

