java - How do you get the last character of a string? -


i've being trying last character of string nothing works except charat(strlength - 1). need declare static variable , convert array one. lone story short it's not working me reason:

/** * note java console applications need run through java runtime * running "java -jar jarfile.jar" in command line. * java console applications can not previewed in compilr ide, applets can. */ public class ispalindrome {      public static boolean status = true;      static string word;     static int strlength = word.length();      public void setword(string word)     {          ispalindrome.word = word;      }        public string[] getword()     {         string[] word = new string[] {"nothign", "super"};         return word;     }      /**     * main entry point application     * @return      */     public static void main(string[] args)      {         if (status == false )         {             system.out.println("you didn't entered palindrome");         }         else          {             system.out.println("you entered palindrome" + get.word);         }      }         public static void isvalidempnum(string[] array, string s)     {          if(s.charat(0) == s.charat(strlength - 1))             status = true;         else             status = false;          return;      } } 

the code:

jcomeau@intrepid:/tmp$ cat test.java public class test {     public static void main(string args[]) {         string string = args[0];         system.out.println("last character: " +                            string.substring(string.length() - 1));      } } 

the output:

jcomeau@intrepid:/tmp$ java test abcdef last character: f 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -