Skip to content

Instantly share code, notes, and snippets.

@JorgeOlvera
Last active August 29, 2015 13:56
Show Gist options
  • Save JorgeOlvera/8970139 to your computer and use it in GitHub Desktop.
Save JorgeOlvera/8970139 to your computer and use it in GitHub Desktop.
/* Returnthesumofthenumbersinthearray,returning0foranempty array.
Except the number 13 is very unlucky, so it does not count and numbers
that come immediately after a 13 also do not count.
sum13({1, 2, 2, 1}) → 6
*/
import java.util.Scanner;
public class internalsum{
public static void main(String [] args)
{
Scanner input = new Scanner (System.in);
int para1 = input.nextInt();
int[] myArr = new int[para1];
for(int i = 0 ; i < myArr.length ; i++){
myArr[i] = input.nextInt();
}
int zum = sum(myArr);
System.out.println(zum);
}
public static int sum(int[] myArr){
int sums = 0;
if(myArr.length == 0){
sums = 0;
}
else{
for(int i = 0 ; i < myArr.length ; i++)
{
if( myArr[i] == 13)
{
myArr[i] = 0;
} else {
sums += myArr[i];
}
}
}
return sums;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment