+ 2

Please i need help with this java program

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

19th Dec 2022, 8:47 PM
Joseph
Joseph - avatar
3 Antworten
0
What is your task here..? One error I can see is kt is Uninitilized. Put kt = 0; before loop.
19th Dec 2022, 9:10 PM
Jayakrishna 🇮🇳
+ 1
Thanks
19th Dec 2022, 9:56 PM
Joseph
Joseph - avatar
0
No problem
20th Dec 2022, 5:03 PM
Ivan Ershov
Ivan Ershov - avatar