Commit 681c0514 authored by Karla Espiritu's avatar Karla Espiritu

Update sumaKata.java

parent 05bdf980
//import java.util.Scanner;
public class sumaKata {
public static void main (String[] args)
{
int numeroDeNumeros = 11;
int [] ls = new int[numeroDeNumeros];
int [] lsSuma = new int[numeroDeNumeros+1];
/*
* ls = [744125, 935, 407, 454, 430, 90, 144, 6710213, 889, 810, 2579358]
*/
ls[0] = 744125;
ls[1] = 935;
ls[2] = 407;
ls[3] = 454;
ls[4] = 430;
ls[5] = 90;
ls[6] = 144;
ls[7] = 6710213;
ls[8] = 889;
ls[9] = 810;
ls[10] = 2579358;
lsSuma = parts_sums(ls);
System.out.print("ls = [ ");
for(int i=0; i<numeroDeNumeros; i++)
{
System.out.print(ls[i] + ",");
}
System.out.println("]");
System.out.print("lsSuma = [ ");
for(int i=0; i<numeroDeNumeros+1; i++)
{
System.out.print(lsSuma[i] + ",");
}
System.out.print("]");
}
public static int [] parts_sums(int [] ls)
{
int suma= 0;
for(int i=0; i<ls.length; i++)
{
suma = suma + ls[i];
}
int [] lsSuma = new int[ls.length +1];
lsSuma[0] = suma;
for(int i=1; i<lsSuma.length; i++)
{
lsSuma[i] = lsSuma[i-1] - ls[i-1];
}
return lsSuma;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment