Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Challenge: Working with Collections | Control Flow and Collections
Android Development with Kotlin

bookChallenge: Working with Collections

You have a list of student grades. Your task is to calculate the average grade and determine the number of students with grades above 80.

Instructions

  • Use a for loop to iterate through the list and find:

    • The average grade.
    • The number of students with grades above 80.
  • Print the average grade and the number of students with grades above 80.

Main.kt

Main.kt

copy
123456789101112131415161718
fun main() { val grades = listOf(75, 88, 92, 66, 80, 95, 72, 85) var sum = 0 var countAbove80 = 0 for (___ in ___) { sum = ___; if (grade ___) { // increment the count value } } val average = //divide sum by count of grades println("Average grade: $average") println("Number of students with grades above 80: $countAbove80") }
  • Use variables to store the sum of the grades and the number of students with grades above 80.
  • To calculate the average grade, use the formula: sum / count.
12345678910111213141516171819
fun main() { // Create a list of student grades val grades = listOf(75, 88, 92, 66, 80, 95, 72, 85) // Find the average grade and the number of students with grades above 80 var sum = 0 var countAbove80 = 0 for (grade in grades) { sum += grade if (grade > 80) { countAbove80++ } } val average = sum / grades.size println("Average grade: $average") println("Number of students with grades above 80: $countAbove80") }
copy

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 4

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Suggested prompts:

Mi faccia domande su questo argomento

Riassuma questo capitolo

Mostri esempi dal mondo reale

Awesome!

Completion rate improved to 5.26

bookChallenge: Working with Collections

Scorri per mostrare il menu

You have a list of student grades. Your task is to calculate the average grade and determine the number of students with grades above 80.

Instructions

  • Use a for loop to iterate through the list and find:

    • The average grade.
    • The number of students with grades above 80.
  • Print the average grade and the number of students with grades above 80.

Main.kt

Main.kt

copy
123456789101112131415161718
fun main() { val grades = listOf(75, 88, 92, 66, 80, 95, 72, 85) var sum = 0 var countAbove80 = 0 for (___ in ___) { sum = ___; if (grade ___) { // increment the count value } } val average = //divide sum by count of grades println("Average grade: $average") println("Number of students with grades above 80: $countAbove80") }
  • Use variables to store the sum of the grades and the number of students with grades above 80.
  • To calculate the average grade, use the formula: sum / count.
12345678910111213141516171819
fun main() { // Create a list of student grades val grades = listOf(75, 88, 92, 66, 80, 95, 72, 85) // Find the average grade and the number of students with grades above 80 var sum = 0 var countAbove80 = 0 for (grade in grades) { sum += grade if (grade > 80) { countAbove80++ } } val average = sum / grades.size println("Average grade: $average") println("Number of students with grades above 80: $countAbove80") }
copy

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 4
some-alt