// Method-I:
- public class SumValueOfArrayAlgorithm {
- public static void main(String[] args) {
- int a[] = { 1, 3, 4, 5, 56, 4 };
- int sum = 0;
- for (int i : a) {
- sum = sum + i;
- }
- System.out.println(sum);
- }
- }
Output: 73
// Method-II:
- public class SumValueOfArrayAlgorithm {
- public static void main(String[] args) {
- int a[] = { 1, 3, 4, 5, 56, 4 };
- int sum = 0;
- for (int i = 0; i < a.length; i++) {
- sum = sum + a[i];
- }
- System.out.println(sum);
- }
- }
No comments:
Post a Comment