kotlin 计算平方_Kotlin程序可计算和显示学生成绩

kotlin 计算平方

Given student's marks in multiple subjects, we have to find and print student grade.

给定学生在多个学科中的成绩,我们必须查找并打印学生成绩。

Consider the following conditions,

考虑以下条件,

    Percentage >=80 -> A
    Percentage >=60 -> B
    Percentage r>=40 -> C
    else D

    Note: Maximum Marks 100 in Each Subject

Example:

例:

    Input:
    Hindi = 67
    English = 98
    Physics = 34
    Chemistry = 67
    Maths = 90

    Output:
    Total Marks = 356.0
    Percentage = 71.2
    Grade = B

在Kotlin计算和显示学生成绩的程序 (Program to calculate and display student grades in Kotlin)

package com.includehelp

import java.util.*

//Main Function , Entry point of Program
fun main(args: Array<String>) {

    //array of subjects Names
    val subjectName = arrayOf<String>("Hindi","English","Physics","Chemistry","Maths")

    //Input Stream
    val scanner = Scanner(System.`in`)

    //Declare Array to Contain Subjects marks
    val marksArray = DoubleArray(5)

    //Start Input Subjects Marks
    println("Input Marks->")
    for(i in marksArray.indices){
        print("${subjectName[i]} : ")
        marksArray[i] = scanner.nextDouble()
    }

    //Calculate Total Marks in All Subjects
    val total = marksArray.sum()

    //Calculate Percentage
    val percentage = marksArray.average()

    //Print Total and Percentage
    println("Total of All subjects Marks : $total")
    println("Percentage : $percentage")


    //To find out Grade based on Percentage
    when{
        percentage>80 -> println("Grade : A")
        percentage>60 -> println("Grade : B")
        percentage>40 -> println("Grade : C")
        else -> println("Grade : D")
    }
}

Output

输出量

Run 1:
Hindi : 67
English : 98
Physics : 34
Chemistry : 67
Maths : 90
Total of All subjects Marks : 356.0
Percentage : 71.2
Grade : B
---
Run 2:
Hindi : 56
English : 32
Physics : 98
Chemistry : 67
Maths : 12
Total of All subjects Marks : 265.0
Percentage : 53.0
Grade : C


翻译自: https://www.includehelp.com/kotlin/calculate-and-display-student-grades.aspx

kotlin 计算平方

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值