Computer Science, asked by sanskartakalkar, 3 months ago

write a program to read 5 elements from user and store in vector and display again​ in java​

Answers

Answered by anindyaadhikari13
0

Solution:

This is written in Java -

import java.util.*;

public class Java_Vector{

   public static void main(String args[]){

       Scanner sc=new Scanner(System.in);

       Vector<Integer> b = new Vector<Integer>();  

       System.out.println("Enter 5 Numbers..");

       for(int i=0;i<5;i++){

           System.out.print(">> ");

           b.add(sc.nextInt());

       }

       System.out.println("The Array is: "+b);

   }

}

Note: To add elements in Vector, use add() method.

See the attachment for output.

•••♪

Attachments:
Similar questions