Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,152 questions

40,706 answers

573 users

How to print an int array in Java

Freaking Awesome WordPress Hosting
141 views
asked Jul 20, 2020 by avibootz
edited Feb 19, 2021 by avibootz

3 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        int arr[] = {1, 28, 9, 3, 5};  
 
        for (int n : arr) {
            System.out.println(n);
        }
    }
}
 
 
 
/*
run:
 
1
28
9
3
5
 
*/

 





answered Jul 20, 2020 by avibootz
0 votes
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        int arr[] = {1, 28, 9, 3, 5};  

        System.out.println(Arrays.toString(arr));
    }
}



/*
run:

[1, 28, 9, 3, 5]

*/

 





answered Jul 20, 2020 by avibootz
0 votes
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        int arr[] = {1, 28, 9, 3, 5};  
 
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}
 
 
 
/*
run:
 
1
28
9
3
5

*/

 





answered Jul 20, 2020 by avibootz
edited Jul 20, 2020 by avibootz

Related questions

3 answers 110 views
1 answer 69 views
1 answer 55 views
2 answers 95 views
...