+ 1
Fill in the blanks to calculate the sum of myArray's elements using the for loop, and print it to the screen. myArray is an arra
Answer pls
9 Antworten
+ 2
I think this code can help you in finding the sum of elements using a "for" loop but you can even use loops like "for each" ,"switch".
class Arraydemo
{
public static void main(String args[])
{
int sum=0;
int i;
int arra[]=new int[5];
arra[0]=0;
arra[1]=1;
arra[2]=2;
arra[3]=3;
arra[4]=4;
for(i=0;i<5;i++)
{
sum=sum+arra[i];
}
System.out.println("sum="+sum);
}
}
+ 2
$items = array("one", "two", "three");
foreach($items as $item) {
echo $item."<br />";
}
+ 1
where are the blanks.....I can't see them!!!
+ 1
//u can also use enhanced for loop
int sum =0;
int [] arra={2,3,4};
for (int t:arra)
sum +=t;
System.out.print (sum),
//output will be 9
//hope it helps ☺
0
Fill in the blanks to print the elements of the array using the foreach loop.
$items = array("one", "two", "three");
foreach
($items
as
$item) {
echo $
."<br />";
}
0
can check this code
0
$items = array("one", "two", "three");
foreach($items as $item) {
echo $item."<br />";
}
0
Fill in the blanks to print the elements of the array using the for loop:
0
Nice
'