code for five digits
How do you restrict a java program to use just the last five numbers. For example if I type in 5678955. The program would only use 78955 and if I only type in 4 numbers the java program tells the user that you didn't type enough numbers try again.
Make a simple buffer or queue? If you made some kind of buffer, you could make it only hold 5 digits, and as more digits are added, the initial ones get popped off. If the size of the buffer was smaller than 5, you could prompt for more input!
Note that expressions like "the last five numbers" are most naturally interpreted as statements about Strings not numeric quantities. Your task would not be noticably different if colour words, people's names, etc rather than numerals were being input.
I would, therefore, read the input as a String (ie not use Scanner's ability to return an int) and then use the String methods to get the length of the string and, if necessary, obtain a substring. Finally I would use Integer.parseInt to obtain the number and check that the String is a well formed integer numeral.
(This assumes that you are after an integer value - if you are after something else like a floating point value or a whole number etc the last step will change.)