java - Array Printf issue -
i'm working on simple program supposed list numeric values in array; way. how have output like:
printing array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
it has lined seen above , line must contain 10 numbers. seem have formatted correctly output doesn't that.
here getting:
printing array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
i'm not sure i'm doing wrong here's code:
//disregard name 'juice', give programs weird names public class juice { public static void main(string[] args) { //sets array int[] numbers = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22}; //title system.out.println("printing array: "); //counting elements (int = 0; < numbers.length; i++) { //prints each element value 4 spaces in between system.out.printf("%4d", numbers[i]); //once line reaches ten values; print new line if (i % 10 == 0) { system.out.printf("\n"); } } } }
if ((i+1) % 10 == 0) { system.out.printf("\n"); }
Comments
Post a Comment