Hi all,
I am very new to Java Programming and am currently trying to write a program to return the last character of a string, entered by the user.
So far I have this:
import java.util.Scanner;
public class lastString
{
public static void main (String[] args)
{
String string1;
Scanner keyboard = new Scanner (System.in);
System.out.print("Enter a String: ");
string1 = keyboard.nextLine();
System.out.println("String Length = ");
System.out.println(string1.length());
System.out.println("The last Character is:");
System.out.println(string1.charAt(0));
}
}
I understand you have to use the length() and charAT methods, but do not know how to return only the last character. (Currently the program returns the first character).
Thanks for looking :)