class 8 output in java
solve the series________________#_#
NO SPAM
Attachments:
hermoinegranger7:
help me out
Answers
Answered by
3
Hi
Finally I solved it!
var range = 8;
var totalOfLastFourNumbers = 0;
var lastFourNumbers = [];
var result = [];
for (var i = 1; i <= range; i++) {
lastFourNumbers.push(i);
result.push(i);
if (lastFourNumbers.length == 4) {
for (var j = 0; j < 4; j++) {
totalOfLastFourNumbers += lastFourNumbers[j];
}
result.push(totalOfLastFourNumbers);
totalOfLastFourNumbers = 0;
lastFourNumbers = [];
}
}
document.write(result);
I hope you can convert it in whatever language you want.
Attachments:
Answered by
4
public class Program
{
public static void main(String[] args) {
int i=1;
int count=0;
int sum=0;
do{
System.out.print(i+" ");
count++;
sum+=i;
if(count%4==0){
System.out.print(sum+" ");
sum=0;
}
}while(i++<8);
}
}
Attachments:
Similar questions
Computer Science,
7 months ago
Science,
7 months ago
Economy,
1 year ago
Math,
1 year ago
Science,
1 year ago