Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Filling a 2d array with preset characters using loops?

$
0
0
Does anyone know how to fill this 2d array with a loop??

String s = "AABBCCDDEEFF"

String input[][];
input = new String [4][3];

input [0][0]= s.substring(0, 1); 
input [0][1]= s.substring(1, 2); 
input [0][2]= s.substring(2, 3); 
input [1][0]= s.substring(3, 4); 
input [1][1]= s.substring(4, 5); 
input [1][2]= s.substring(5, 6); 
input [2][0]= s.substring(6, 7); 
input [2][1]= s.substring(7, 8); 
input [2][2]= s.substring(8, 9); 
input [3][0]= s.substring(9, 10); 
input [3][1]= s.substring(10, 11); 
input [3][2]= s.substring(11, 12);  


This is the way that i did it before but i need to make it more efficient. I have tried the loops thing and have asked some friends (beginners at java like myself) but it just doesnt work. I think the main problem is that i dont know how to pick out characters from the string to place in the array. Any help is appretiated! Also i dont really get the nested loop thing which im pretty sure you need to get the array position you want to fill?

Thanks in advance!!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>