Computer Science, asked by akashavati40, 3 months ago

10. Write the program to segment to read and print one dimensional array
clement​

Answers

Answered by BrainlyProgrammer
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:-

  1. i :- Loop variable
  2. n:- to accept size of the array
  3. a:- To store array elements

__________

•Output Attached

Attachments:
Similar questions