SORU
2 Mart 2011, ÇARŞAMBA


Nasıl bir dizenin son karakteri alabilirim?

Bir dizenin son karakteri almak için çalışıyor ettik ama hiçbir şey charAt(strLength - 1) dışında çalışır. Statik bir değişken bildirmek ve benim dizi dönüştürmek istiyorum. Yalnız lafın kısası bu nedense benim için çalışmıyor:

/**
* Note that Java console applications need to be run through the java runtime
* by running "java -jar JarFile.jar" in the command line.
* Java console applications can not be previewed in the Compilr IDE, only 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;
    }

    /**
    * This is the main entry point for the application
    * @return 
    */
    public static void main(String[] args) 
    {
        if (status == false )
        {
            System.out.println("You didn't entered a Palindrome");
        }
        else 
        {
            System.out.println("You entered a 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;

    }
}

CEVAP
2 Mart 2011, ÇARŞAMBA


Kod:

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)); 
    }
}

Çıkış:

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

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • 3dmmfavs

    3dmmfavs

    29 Kasım 2009
  • Android Police

    Android Poli

    21 NİSAN 2010
  • DanceOn

    DanceOn

    6 Mayıs 2006