Created
October 29, 2017 15:21
-
-
Save PocasPedro/4eb1b7c4126dca89dca8b4fb1c788950 to your computer and use it in GitHub Desktop.
Java Fundamentals for Kids - Exercise 20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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