I need someone to explain the output of this program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I need someone to explain the output of this program

import java.util.Scanner; public class Sample12 { public static void main(String[] args) { int sum = 0; float avg; float[] scores = new float[15]; float[] ans = new float[15]; //Declare refrence variable of type Scanner Scanner input = new Scanner(System.in); //To compute sum and product for(int i=0; i<15; i++) { scores[i] = input.nextFloat(); sum += scores[i]; ans[i] = scores[i] * 3; } avg = sum/15; //Print results System.out.println("\n\tThe average =" +avg); for(int i=0; i<15; i++) { System.out.println(ans[i]); } } }

8th Jan 2023, 3:49 PM
Joseph
Joseph - avatar
2 Answers
0
The output prints the 'avg' variable that is 'sum of int score[]' divided by 'total numbers'. It also prints the 'ans[]' that is 'score[] * 3'.
8th Jan 2023, 6:02 PM
Prashant Narendra Solanki
Prashant Narendra Solanki - avatar
0
This is a Java program that computes the average and triple of a list of 15 floating-point numbers. The program begins by declaring an integer sum and a float avg, and two arrays of 15 floating-point numbers: scores and ans. It also creates a Scanner object called input which will be used to read input from the user.
8th Jan 2023, 6:11 PM
Aditya Dixit