Go to Top

Wednesday 5 October 2011

To separate the digits of a number

Question 56 : Write a program in Java to separate the digits of a number taken as input from the user.

Java Program :

import java.io.*;
class separate
{
 static void main()throws IOException
 {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     int i;
     String a;
     System.out.print("Enter the number : ");
     a=br.readLine();
     System.out.print("\nThe digits are : ");
     for(i=0;i<=a.length()-1;i++)
     {
         System.out.print(a.charAt(i));
         if(i!=a.length()-1)
         System.out.print(" , ");
         else
         System.out.print(" .");
        }
    }
}
     

No comments:

Post a Comment

ShareThis