The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Array demo
By Guest on 7th October 2024 07:43:43 AM | Syntax: TEXT | Views: 28



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. //wap to enter the no of elements in an array and store it in an array and display it
  2. import java.io.*;
  3.  
  4.  
  5. public class Arraydemo {
  6.     public static void main(String[] args) {
  7.         try {
  8.             DataInputStream in = new DataInputStream(System.in);
  9.             System.out.println("Enter the no of elements in an array");
  10.             int n = Integer.parseInt(in.readLine());
  11.             int arr[] = new int[n];
  12.             System.out.println("Enter the elements in an array");
  13.             for (int i = 0; i < n; i++) {
  14.                 arr[i] = Integer.parseInt(in.readLine());
  15.             }
  16.             System.out.println("The elements in an array are");
  17.             for (int i = 0; i < n; i++) {
  18.                 System.out.println(arr[i]);
  19.             }
  20.         }
  21.        
  22.         catch (Exception e) {
  23.         }
  24.        
  25.         }
  26.  }





array demo    





  • Recent Pastes