Jump to content

Recommended Posts

Posted (edited)

Pessoal tenho outra duvida sobre vectores.

Tenho de fazer um programa que dado um vector por exemplo(1,2,3,4,5) retorna o vector(3,4,5) ou seja a segunda metade do vector incluindo o termo do meio caso o comprimento seja impar


static int[] secondHalf(int[] v, boolean includeMiddle)
{
int i= v.length/2;
int [] v1= new int [v.length];

while (i<(v.length))
{
if (v.length%2==1)
{
v1[i]=v[v.length/2-v.length%2];
}
v1[i]=v[i];
i=i+1;
}
return v1;
}

o código está mal e o meu problema reside no modo vamos definir o tamanho do novo vector.

Edited by Masato

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.