+ 1

Whats the solution here?

can someone help me get the output for this solution.? https://code.sololearn.com/c5dMjBbIizaI/?ref=app

21st Jul 2019, 9:51 AM
Jinyoongisaranghe
Jinyoongisaranghe - avatar
3 Answers
+ 1
change 5 to 4 in this line // for(int j=i;j<5;j++) for(int j=i;j<4;j++) if j is 4 you cant do a[j+1] because max index is 4
21st Jul 2019, 10:14 AM
zemiak
+ 1
https://www.sololearn.com/learn/4562/?ref=app my intention was of solving this sum . and my program was a trial to print the sum in all sorts of ways, instead of finding which is greater could you help in that sort??
21st Jul 2019, 3:04 PM
Jinyoongisaranghe
Jinyoongisaranghe - avatar
0
add sum=0; after loop j and loop k for(int i=0;i<5;i++) { for(int j=i;j<4;j++) { System.out.print( "("+a[j]+"*"+a[j+1]+")+" ); sum = sum + (a[j]*a[j+1]); } if(i<4) System.out.println(" = "+sum); sum = 0; for(int k=0;k<i;k++) { System.out.print( "("+a[k]+"*"+a[k+1]+")+" ); sum=sum+(a[k]*a[k+1]); } if(i>0) System.out.println(" = "+sum); sum = 0; }
21st Jul 2019, 6:39 PM
zemiak