handle array of numbers


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: handle array of numbers

  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Post handle array of numbers

    If you have an array of numbers like (00,245,34,675,109) and i want to put it in 2 dimensional array so that each number would be in an array and how can i perform it so that it the units would be in the last cell following by the tenth till the end

    MANY THANKS FOR CONSIDERATION

  2. #2
    Join Date
    Oct 2010
    Posts
    10

    Thumbs up check this out :solution to your problem

    Code:
    class demoArray
    {
    	public static void main (String args[])
    	{
    		int ary[]={0,245,34,675,109};
    		int ary2[][]=new int[5][3];
    		//int ary2[][]=new int[][] {{1,0,0},{0,1,0},{1,2,1}};
    
    		for(int i=0;i<ary.length;i++)
    			{
    				int j=ary[i];
    				if(j==0)
    				{
    					for(int x=0;x<ary2[i].length;x++)
    						ary2[i][x]=0;
    				}
    
    				else
    				{
    					int x=ary2[i].length-1;
    
    					while(j>=0 && x>=0)
    					{
    						int r;
    						r=j%10;
    						j=j/10;
    						ary2[i][x]=r;
    						x--;
    
    					}
    				}
    			}
    			for (int i=0;i<=ary.length;i++)
    			{
    				for(int j=0;j<ary2[i].length;j++)
    					System.out.print(" "+ary2[i][j]);
    				System.out.println();
    			}
    
    
    	}
    }

Similar Threads

  1. Replies: 8
    Last Post: 05-15-2009, 10:54 AM
  2. Reversing an Array
    By Tmcclain in forum Java
    Replies: 7
    Last Post: 02-13-2009, 11:57 PM
  3. Find the mode of the numbers in a array
    By kreeksk in forum Java
    Replies: 1
    Last Post: 02-25-2007, 04:14 PM
  4. Replies: 1
    Last Post: 05-31-2006, 03:14 AM
  5. Replies: 2
    Last Post: 04-15-2005, 10:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center