static methods - single dimensional array print through foreach loop -


how can print elements of single dimensional array via foreach loop method

public class singlearrayprac {      public static void main(string[] args) {         int[] array = { 1, 2, 3, 4 };          // for(int row : array)  way can print array want print through method, how?         // system.out.println(row);         (int print : array) {             printrow(print);         }     }      public static void printrow(int row) {         (int print : row) { // error @ row             system.out.println(print);         }     } } 

your problem lies declare printrow method. pass int should pass int[] array. causes error because trying on variable not collection of data. should so:

public static void printrow(int[] row) {      (int print : row) {          system.out.println(print);     } } 

now when want print array call printrow(array) array int[].


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -