Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an application that finds the total and average of odd numbers from 1 to 1

ID: 3622860 • Letter: W

Question

Write an application that finds the total and average of odd numbers from 1 to 15. Your program must use a counted loop to accomplish this task. Output the odd numbers from 1 to 15, the sum of those numbers and the average of those numbers as shown below:

1 3 5 7 9 11 13 15
Sum is: 64
Average: 8.0

Process completed.

Compile and run your program until it works and the output looks nice. Add the necessary documentation as described in Course Documents, and then attach your .java file to this assignment. Do not attach the .class file, attach only the .java source code.

Explanation / Answer

please rate - thanks

import java.util.Scanner;
public class main {
public static void main(String[] args)
{Scanner in = new Scanner(System.in);
int i,sum=0,count=0;
double average;
for(i=1;i<=15;i++)
{if(i%2==1)
   {System.out.print(i+" ");
    count++;
    sum+=i;
    }
}
System.out.println();   
System.out.println("Sum is: "+sum);
average=sum/(double)count;
System.out.println("Average is: "+average);

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote