I'm just starting to use Netbeans and I'm reading up on recursion, but there's a simple exercise I'm having trouble with. Does anyone know how to fix it?
Write a program that allows you to fill a vector recursively and copy its contents in the same way to another vector. Recursively adds both vectors and displays both vectors along with the result of the addition.
Code:
recursive package Vectorx;
import javax.swing.JOptionPane;
public class VectorCalc {
public void fillVector(int vec[],int x){
if(x<10){
vec[x]=Integer.parseInt(JOptionPane.showInputDialog(null,
"Enter a number:"));
fillvector(vec,x+1);
}
}
public void displayVector(int vec[],int x){
if(x<10){
System.out.print(vec[x]+" ");
showVector(vec,x+1);
}
}
Major:
main public class {
public static void main(String[] args) {
VectorCalc v=new VectorCalc();
int vec[]=new int[10],x=0;
int vec2[]=Arrays.copyOf(vec, vec.length);
int vec3[]=new int[10],x=0;
v.fillVector(vec, 0);
v.displayVector(time,0);
for(int i =0; i < 10; i++ ){
vec3[i]=vec[i]+vec2[i];
System.out.println(vec3); //Im trying to add the vectors here in main even though I think its not what I need to do still it doesnt work, it prints some symbols.