Skip to content

Instantly share code, notes, and snippets.

@PocasPedro
Created October 29, 2017 15:21
Show Gist options
  • Save PocasPedro/4eb1b7c4126dca89dca8b4fb1c788950 to your computer and use it in GitHub Desktop.
Save PocasPedro/4eb1b7c4126dca89dca8b4fb1c788950 to your computer and use it in GitHub Desktop.
Java Fundamentals for Kids - Exercise 20
public class SumIsThirty {
public static void main(String[] args) {
//Define & Initialization
int numbers[] = new int[] {10,333,10,6,10,8,14,43};
int sum = 0;
boolean isThirty = false;
for(int i = 0 ; i < numbers.length ; i ++){
if(numbers[i] == 10)
sum += numbers[i];
}
if(sum == 30)
isThirty = true;
if(isThirty == true){
System.out.println("The sum of all 10's in array is 30");
} else
System.out.println("The sum of all 10's in array is not 30");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment