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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,892 questions

51,823 answers

573 users

How to define and use int array in Java

4 Answers

0 votes
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        int[] arr1 = {1, 28, 9, 3, 5};
        int arr2[] = {1, 28, 9, 3, 5};  
        
        System.out.println(Arrays.toString(arr1));
        System.out.println(Arrays.toString(arr2));
    }
}



/*
run:

[1, 28, 9, 3, 5]
[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[] = new int[]{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[] = new int[5];
        
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i;
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i] );
        }
    }
}



/*
run:

0
1
2
3
4

*/

 



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

public class MyClass {
    public static void main(String args[]) {
        int arr[] = new int[7];
        
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i;
        }

        for (int n : arr) {
            System.out.println(n);
        }
    }
}



/*
run:

0
1
2
3
4
5
6

*/

 



answered Jul 20, 2020 by avibootz

Related questions

1 answer 179 views
1 answer 132 views
2 answers 122 views
122 views asked Jul 20, 2020 by avibootz
1 answer 127 views
2 answers 191 views
2 answers 159 views
1 answer 215 views
...