One-dimensional arrays in Java are arrays that contain only one dimension. In other words, they can store elements but cannot be used to store other arrays.
To declare a one-dimensional array in Java, you need to specify the type of the elements and the number of elements in the array. Here's the general syntax for declaring a one-dimensional array:
package array;
import java.util.*;
public class OneD {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the digit number:");
int n = sc.nextInt();
int num[] = new int[n];
System.out.println("Enter numbers :");
for (int i = 0; i < n; i++) {
num[i] = sc.nextInt();
}
System.out.println("You entered :");
for (int i = 0; i < n; i++) {
System.out.println(num[i]);
}
sc.close();
}
}
Comments
Post a Comment