java - Printing an array in a table format -
i have array filled 50 numbers , cannot figure how output array table format.
currently when print array being outputted 1 long line of numbers, , aiming 10 lines, each consisting of 5 numbers.
furthermore prefer each value 3 digit value. 1 represented 001, improve readability , presentation.
import java.util.*; public class random50 { public static void main (string[] args) { final int max_size = 50; int[] r50 = new int[max_size]; random rand = new random(); (int i=0; i<r50.length; i++) { r50[i] = rand.nextint(1000); (int j=0;j<i;j++) { if (j!=i && r50[i] == r50[j]) { system.out.println("duplicate: " + r50[i]); r50[i] = rand.nextint(1000); } } } system.out.printf(arrays.tostring(r50)); } }
you should ask 1 question per post i'll answer first question - makes other users can find relevant information in future (not trying mean).
if want start printing on new line every fifth number make use of modulus
operator %
.
for(int = 0; < 50; i++){ if(i % 5 == 0){ // true every fifth value system.out.print("\n"); // print new line } ... // other code goes here }
Comments
Post a Comment