Loading...
Loading...
Loading...
A bus conductor checks ticket codes quickly by looking at the first and the last character, and at the length. Read a ticket code and print its length, its first character and its last character.
Length: n, First: x and Last: y.Example 1
Input
KA01-7788
Output
Length: 9 First: K Last: 8
The dash counts as a character.
Example 2
Input
A
Output
Length: 1 First: A Last: A
With one character, first and last are the same.
Try the problem first. Open one hint at a time.
length() gives the number of characters.
The first character is at index 0. The last one is at index length() - 1, not length().
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor