V Help Tell me what you want to do Emphasis Heading 1 1Normal Strong Paragraph S
ID: 3753698 • Letter: V
Question
V Help Tell me what you want to do Emphasis Heading 1 1Normal Strong Paragraph Styl 1. Use NetBeans IDE to do the following Start NetBeans. Please create a new project in a folder in your H: drive or your own flash drive and name your new project as: a. b. COSC241 "; vector.add (wzappeint): vector-add (atr): vester.add(2, new Integer (2138)): Sxatem.cut pxinsin ("The elements of vector: vector): Syetem.out printin ("The size of vector is:" sxetem.out.prAntin ( "The elements at position 2 1s: Syetem.outRrintia("The first element of vector is: Svatem ouE REANtin("The last element of vector is: + xeatok elementRt (2)) + vecton.firstElement 0): + vector.lastElenent )): Svecem.cut prinEin(The elements of vector: Svecem.ct.pxanain("The aize of vector is: vector) Sxstem.qutprintin("The elements at position 2 i5:" Syetem.cutapxinain ("The first element of vecton is: t tectoa.elementAt (2))7 t prsnalin ("The Last element of vector Ja:Explanation / Answer
VectorDemo.java
import java.util.Random;
import java.util.Vector;
public class VectorDemo {
public static void main(String[] args) {
//Creating a random Class object
Random r = new Random();
Vector<Object> vector=new Vector<Object>();
int primitiveInt=241;
Integer wrapperInt=new Integer(1234);
String str="Kane";
vector.add(primitiveInt);
vector.add(wrapperInt);
vector.add(str);
vector.add(2,new Integer(2318));
System.out.println("The Elements of vector:"+vector);
System.out.println("The size of vector is :"+vector.size());
System.out.println("The Element at position 2 is :"+vector.elementAt(2));
System.out.println("The first Elementof vector is :"+vector.firstElement());
System.out.println("The last Elementof vector is :"+vector.lastElement());
vector.removeElementAt(1);
System.out.println("The Elements of vector:"+vector);
System.out.println("The size of vector is :"+vector.size());
System.out.println("The Element at position 2 is :"+vector.elementAt(2));
System.out.println("The first Elementof vector is :"+vector.firstElement());
System.out.println("The last Elementof vector is :"+vector.lastElement());
//Inserting 3 random Numbers Between 10 and 30 into the vector
for(int i=0;i<3;i++)
{
vector.add(r.nextInt((20) + 1) + 10);
}
System.out.println("The Elements of vector:"+vector);
System.out.println("The size of vector is :"+vector.size());
//Removing all elements in the odd index
for(int i=1;i<vector.size();i++)
{
vector.removeElementAt(i);
}
//After Removing the odd indexed elements in the vector
System.out.println("The Elements of vector:"+vector);
System.out.println("The size of vector is :"+vector.size());
}
}
_________________
Output:
The Elements of vector:[241, 1234, 2318, Kane]
The size of vector is :4
The Element at position 2 is :2318
The first Elementof vector is :241
The last Elementof vector is :Kane
The Elements of vector:[241, 2318, Kane]
The size of vector is :3
The Element at position 2 is :Kane
The first Elementof vector is :241
The last Elementof vector is :Kane
The Elements of vector:[241, 2318, Kane, 24, 11, 19]
The size of vector is :6
The Elements of vector:[241, Kane, 11]
The size of vector is :3
_____________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.