DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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, 09:54 AM
  2. Reversing an Array
    By Tmcclain in forum Java
    Replies: 7
    Last Post: 02-13-2009, 10:57 PM
  3. Find the mode of the numbers in a array
    By kreeksk in forum Java
    Replies: 1
    Last Post: 02-25-2007, 03:14 PM
  4. Replies: 1
    Last Post: 05-31-2006, 02:14 AM
  5. Replies: 2
    Last Post: 04-15-2005, 09:06 PM

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links