10. Write the program to segment to read and print one dimensional array
clement
Answers
Answered by
2
Question:-
- WAP to accept and print one-dimensional array elements.
________
Answer:-
package Coder;
import java.util.*;
public class Array {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter size of the array:");
int n=sc.nextInt();
int a[]=new int[n];
System.out.println("Enter elements in the array");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
System.out.println("Elements of the array are:-");
for(int i=0;i<n;i++)
{
System.out.println(a[i]);
}
}
}
___________
Variable Description:-
- i :- Loop variable
- n:- to accept size of the array
- a:- To store array elements
__________
•Output Attached
Attachments:
Similar questions