This is the answer for your problem.
try, this code it is going exactly what you want...


import java.io.*;
public class number
{
public static void main(String[] args)throws IOException...