How do I get the last character, then last two so on.. of a string?

You need to replace the charAt method with the substring method:

String vacantion = "Vacantion";

int number = 1;

for (int i = 0; i < vacantion.length(); i++)
{
    System.out.println(vacantion.substring(vacantion.length() - number));

    number++;
}

Browse More Popular Posts

Leave a Comment