Skip to content
Snippets Groups Projects
Commit f3ae2832 authored by Mika Pohto's avatar Mika Pohto
Browse files

TaulukkoApumetodit lisätty

parents
No related branches found
No related tags found
Loading
public class TaulukkoApumetodit
{
/* @param taulukko
* @return
*/
public static int[] annaPositiiviset(int[] taulukko)
{
int n = 0;
for(int num: taulukko)
if(num >= 0) n++;
int[] t = new int[n];
for(int i = 0, j = 0; i < n; i++, j++)
{
if(taulukko[j] >= 0)
t[i] = taulukko[j];
else
i--;
}
return t;
}
/* @param taulukko
* @param indeksi
* @return
*/
public static int[] poista(int[] taulukko, int indeksi)
{
int i = 0;
int[] t = new int[taulukko.length - 1];
for(i = 0; i < indeksi; i++)
t[i] = taulukko[i];
for(++i; i < taulukko.length; i++)
t[i-1] = taulukko[i];
return t;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment