write a program to read 5 elements from user and store in vector and display again in java
Answers
Answered by
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
History,
1 month ago
Political Science,
1 month ago
Math,
3 months ago
English,
10 months ago
Chemistry,
10 months ago