* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Alejandra
*/
import java.io.*;
public class Vector {
int[] v1=new int[10];
int[] v2=new int[10];
int cap=0;
int resultado[]=new int[10];
public void setResultado(int[] resultado) {
this.resultado = resultado;
}
public int[] getResultado() {
return resultado;
}
public int getCap() {
return cap;
}
public void setCap(int cap) {
this.cap = cap;
}
public void llenar()throws IOException{
BufferedReader v=new BufferedReader(new InputStreamReader(System.in));
System.out.print ("Cuantos Elementos Desea Que Tenga Sus Dos Vectores: ");
cap=Integer.parseInt(v.readLine());
System.out.println("vector 1: ");
for (int n=1;n<=cap;n++){
System.out.print("Posicion ["+n+"] : ");
v1[n]=Integer.parseInt(v.readLine());
}
System.out.println ("Vector 2: ");
for (int k=1;k<=cap;k++){
System.out.print("Posicion ["+k+"]: ");
v2[k]=Integer.parseInt(v.readLine());
}
}
public void suma()throws IOException{
BufferedReader v= new BufferedReader(new InputStreamReader(System.in));
for (int y=1;y<=cap;y++){
resultado[y]= (v1[y]+v2[y]);
System.out.println("Posicion ["+y+"]: "+resultado[y]+"\n");
}
}
public void resta()throws IOException{
BufferedReader v= new BufferedReader(new InputStreamReader(System.in));
for (int y=1;y<=cap;y++){
resultado[y]=(v1[y]-v2[y]);
System.out.println("Posicion ["+y+"]: "+resultado[y]+"\n");
}
}
public void multiplicacion()throws IOException{
BufferedReader v= new BufferedReader(new InputStreamReader(System.in));
for (int y=1;y<=cap;y++){
resultado[y]=(v1[y]*v2[y]);
System.out.println("Posicion ["+y+"]: "+resultado[y]+"\n");
}
}
}
--------------------------------------------------------------------------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Alejandra
*/
import java.io.*;
public class Mvector {
public static void main (String[]arg)throws IOException{
BufferedReader v=new BufferedReader(new InputStreamReader(System.in));
Vector obj=new Vector();
int op;
do{
System.out.println("\t\tMenu\n");
System.out.println("\t1.Llenar los vectores\n");
System.out.println("\t2.Sumar Vectores\n");
System.out.println("\t3.Restar Vectores\n");
System.out.println("\t4.Multiplicar Vectores\n");
System.out.println("\t5.salir\n");
System.out.println("\t\tEliga su opcion: ");
op=Integer.parseInt(v.readLine());
switch(op){
case 1:
obj.llenar();
break;
case 2:
obj.suma();
break;
case 3:
obj.resta();
break;
case 4:
obj.multiplicacion();
break;
case 5:
break;
}
}while(op!=5);
}
}
Desarrollar una función que permita obtener la raíz cuadrada de un número pasado por parámetro.
ResponderEliminarcomo podria resolver esto porfa