Friday, August 2, 2013

NameValidation

import java.util.Scanner;
public class NameValidation {
   
    public static void main(String[] args) {
      
        Scanner s= new Scanner(System.in);
        String word;
        int lastletter;
      
        do{
            System.out.print("Enter a word: ");
            word = s.next();
            lastletter = word.length()-1;
            if (word.equals("exit")){
            System.out.println("Program is now terminating…");
            break;
            }
            else if (word.charAt(lastletter)==word.charAt(0))
            System.out.println("The first character is EQUAL to its last character: "+word);
            else
            System.out.println("The first character is NOT EQUAL to its last character: "+word);

            }
            while (word != null);

            }

            }

No comments:

Post a Comment