The operation of a little java-vector every day

Source: Internet
Author: User

Package Java_prac2;import java.util.*;/** * <p>title: Vector operations </p> * <p>description: Demonstrates the basic operation of a vector (vectors) </p> * <p>copyright:copyright (c) 2003</p> * <p>Filename:operateVector.java</p> * @ Author Wanghaitao * @version 0.1 */public class Vector_operate{/**<br> method Description: Generate a 4*4 two-dimensional Vector for use.   *<br> input parameters:*<br> output variable:vector*<br> other description: */public vector buildvector () {vector vtemps = new vector ();  for (int i=1;i<5;i++) {vector vtemp = new vector ();  for (int j=1;j<5;j++) {vtemp.addelement ("Vector (" +i+ ") (" +j+ ");   } vtemps.addelement (Vtemp); } return vtemps;} /**<br> Method Description: Insert data *<br> input parameters: Vector vtemp The data object to be inserted *<br> input parameters: int iTemp position of the inserted data *<br> input parameters: Object Otemp Insert data value *<br> output variable: Vector result *<br> Other notes: Assuming that the insertion position exceeds the actual location of the instance will return null*/public vector insert (vector vtemp,int Itemp,object otemp) {if (Itemp>vtemp.size ()) {print ("Data over bounds!"); return null;} else{Vtemp.insertelementat (otemp,itemp);} return vtemp;} /**<bR> Method Description: Remove data *<br> input parameters: Vector vtemp object to be deleted *<br> input parameters: int iTemp location *<br> output variable for deleted data: vector*<br > Other instructions: Assuming that data is removed from the bounds, the null*/public vector Delete (vector vtemp,int iTemp) {if (Itemp>vtemp.size ()) {print ("Data over bounds!") will be returned; return null;} else{Vtemp.removeelementat (iTemp);} return vtemp;} /**<br> method Description: Change data *<br> input parameters: Vector vtemp object to be changed *<br> input parameters: int iTemp location of change data *<br> input parameters: Object Otemp change data value *<br> output variable:vector*<br> Other instructions: Assume that the data that changes the bounds of the position will return null*/public vector updata (vector vtemp,int iTemp, Object otemp) {if (Itemp>vtemp.size ()) {print ("Data over bounds!"); return null;} else{Vtemp.setelementat (otemp,itemp);} return vtemp;} /**<br> Method Description: Output information *<br> input parameters: String stemp Output Information name *<br> input parameters: Object otemp Output Information value *<br> return variable: none */    public void print (String stemp,vector otemp) {System.out.println (stemp+ "Data:"); This.print (otemp);} /** *<br> Method Description: Print output (overload) *<br> Input Parameters: Object Opara output Objects *<br> return type: no */public void Print (Object Opara) {Sy STEM.OUT.PRINTLN (oPara);}   /** *<br> Method Description: Print output (overload) *<br> input parameters: vector Vpara display output vector object *<br> return type: no */public void print (vector vpara) {   for (int i=0;i<vpara.size (); i++) {System.out.println (Vpara.elementat (i)); }}/** *<br> Method Description: Main method, program entry *<br> input parameter: string[] args *<br> return type: No */public static void main (string[] args) {Vector_operate ov = new vector_operate (); Vector vtemp = Ov.buildvector (); Ov.print ("Result of the vector", vtemp);        Vector vresult = Ov.insert (vtemp,2, "");//create a new vector and initialize Ov.print ("Insert Result", vresult);        Vector Vresultup = Ov.updata (vresult,2, ""); Ov.print ("Update results", vresultup); Vector Vresultnow = Ov.delete (vresultup,2); Ov.print ("After delete", Vresultnow);}}

The operation of a little java-vector every day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.