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 parameter:*<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 parameter: Vector vtemp data object to be inserted *<br> input parameter: int iTemp position of inserted data *<br> input parameter: Object Otemp Insert data value *<br> output variable: vector result *<br> Other instructions: If the insertion position exceeds the actual location of the instance, the 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 parameter: int iTemp location *<br> output variable for delete data: vector*<br > Other Instructions: If you delete the data 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: Modify data *<br> input parameters: Vector Vtemp object to be modified *<br> input parameters: int iTemp position of modified data *<br> input parameter: Object Otemp modifying data values *<br> output variables:vector*<br> Other instructions: If you modify the data for the location bounds, the null*/public vector updata (vector vtemp,int iTemp) is returned, 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 parameter: String stemp output Information name *<br> input parameter: 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: PrintOut (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.