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

8. Write some code that inputs a set of int values and computes its average. Ask

ID: 3762078 • Letter: 8

Question

8.

Write some code that inputs a set of int values and computes its average. Ask the user first
how many int values will be input. Make sure that your code cannot produce a division by zero
error. Assume that a Scanner called “Keyboard” has been defined for keyboard input.

9.

Write a set of code that outputs all of the int values between 1 and 100 with 5 values per line,
and each of those 5 values spaced out equally. Use a single for-loop to solve this problem.

8.

Write some code that inputs a set of int values and computes its average. Ask the user first
how many int values will be input. Make sure that your code cannot produce a division by zero
error. Assume that a Scanner called “Keyboard” has been defined for keyboard input.

9.

Write a set of code that outputs all of the int values between 1 and 100 with 5 values per line,
and each of those 5 values spaced out equally. Use a single for-loop to solve this problem.

Explanation / Answer

double average(){
   int n;
   n = keyboard.nextInt();
   for(int i = 0 ; i < n; i++)
       sum += keyboard.nextInt();
   return (double)sum / n;
}

for(int i = 1; i <= 100; i++){
   System.out.print(i + “ ”);
   if( i % 5 == 0)
       System.out.println();
}

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