+ 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

2nd Sep 2017, 8:08 AM
Yaamine
9 odpowiedzi
+ 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); } }
2nd Sep 2017, 8:26 AM
sharath chandra
sharath chandra - avatar
+ 2
$items = array("one", "two", "three"); foreach($items as $item) { echo $item."<br />"; }
17th May 2022, 6:20 AM
Megha Raj kandel
+ 1
where are the blanks.....I can't see them!!!
2nd Sep 2017, 8:25 AM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 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 ☺
2nd Sep 2017, 8:32 AM
Changed
Changed - avatar
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 />"; }
4th Feb 2021, 11:28 PM
ABDOOL MOHAMED
ABDOOL MOHAMED - avatar
0
can check this code
18th May 2021, 1:00 AM
Waleed
Waleed - avatar
0
$items = array("one", "two", "three"); foreach($items as $item) { echo $item."<br />"; }
11th Jan 2022, 2:12 PM
Rugema Didier
0
Fill in the blanks to print the elements of the array using the for loop:
19th Jan 2022, 11:25 AM
Gene Lira
0
Nice '
28th Apr 2022, 7:59 PM
Максетов ТоребеKK