Friday, 15 January 2021

WAP in Java to read and display a Single Dimensional array.

import java.util.*;

public class Main

{

  public static void main(String args[])

  {

  Scanner in=new Scanner(System.in); 

  int N,i;

  System.out.println("Enter the size of the array");

  N=in.nextInt();

  int arr[]=new int[N];

  System.out.println("Enter "+N+" Numbers");

  for(i=0;i<N;i++)

  arr[i]=in.nextInt();

  System.out.println("The elements of the array are:");

  for(i=0;i<N;i++)

  System.out.println(arr[i]);

  }

}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...