//by using assignment statement for integer
// use of length command
class ex_1
{
public static void main(String[]args)
{
int i,sum;
sum=0;
int m[]={2,3,4,5,6}; //0 index 2 1 index 3 2 index 4
int l=m.length;
for(i=0;i<5;i++)
sum+=m[i]; //sum=2+3+4
System.out.println("Length of the array: "+l);
System.out.println("the sum of the array elements ="+sum);
}
}
output
Length of the array: 5
the sum of the array elements =20
// use of length command
class ex_1
{
public static void main(String[]args)
{
int i,sum;
sum=0;
int m[]={2,3,4,5,6}; //0 index 2 1 index 3 2 index 4
int l=m.length;
for(i=0;i<5;i++)
sum+=m[i]; //sum=2+3+4
System.out.println("Length of the array: "+l);
System.out.println("the sum of the array elements ="+sum);
}
}
output
Length of the array: 5
the sum of the array elements =20
No comments:
Post a Comment
any problem in any program comment:-