⇧
Contact Us
||
Privacy Policy
||
About Us
Home
Java
Progarm
PHP
Menu ▼
Program
Vowel or Constant
Area of Circle
Find the Triangle
Compound Interest
Prime Number
Reverse Number
Factorial Number
Sum of Element
User Input
Calculate Average
Even or Odd
N Prime Number
1 to n Prime Number
Reverse String
Reverse String by User
Check Leap Year
HexaDecimal String
Binary to Decimal
Get IP
Check ArmStrong
ArmStrong Or Not
next →
← prev
8) Write a program to Sum of Element Array in Java.
Program
import java.util.Scanner; class SumEx{ public static void main(String args[]){ Scanner scanner = new Scanner(System.in); int[] array = new int[5]; int sum = 0; System.out.println("Enter the elements:"); for (int i=0; i<5; i++) { array[i] = scanner.nextInt(); } for( int num : array) { sum = sum+num; } System.out.println("Sum of array elements is:"+sum); } }
Next Topic
← prev
next →