Java程序示例,用于计算总分和百分比
我们将演示如何使用 Java 程序计算总分和百分比。 总分是指所有可用分数的总和,而术语百分比是指计算分数除以总分并乘以所得的数字100。
percentage_of_marks = (obtained_marks/total_marks) × 100
示例 1
这是一个Java程序,用于演示如何计算总分和百分比。
// Java Program to demonstrate how is Total marks and Percentages calculated import java.io.*; public class TotalMarks_Percent1 { public static void main(String[] args){ int n = 8, t_marks = 0; float percent; // creation of 1-D array to store marks int marks[] = { 69, 88, 77, 89, 98, 100, 57, 78 }; // calculation of total marks for (int j = 0; j < n; j++) { t_marks += marks[j]; } System.out.println("Total Marks is: " + t_marks); // calculate the percentage percent = (t_marks / (float)n); System.out.println("Total Percentage is: " + percent + "%"); } }
输出
Total Marks is: 656 Total Percentage is: 82.0%
在上面的Java程序中,正在计算学生在8门科目中获得的总分和百分比。获得的分数存储在名为marks []的数组中。
总分数被计算并存储在一个名为t_marks的变量中,它们的百分比被计算并存储在一个名为percent的变量中。
这两个值都会进一步显示在控制台上。
Example 2
的中文翻译为:示例2
这是一个Java程序,用于演示从用户输入中计算五个科目的总分和百分比。
// Java program to compute the total marks and percentage of five subjects taken as input from the user import java.util.Scanner; class TotalMarks_Percent2{ public static void main(String args[]){ float FLAT, COA, Networking, Python, AI; double t_marks, percent; Scanner mk =new Scanner(System.in); // Take marks as input of 5 subjects from the user System.out.println("Input the marks of five subjects \n"); System.out.print("Enter marks of FLAT:"); FLAT = mk.nextFloat(); System.out.print("Enter marks of COA:"); COA = mk.nextFloat(); System.out.print("Enter marks of Networking:"); Networking = mk.nextFloat(); System.out.print("Enter marks of Python:"); Python = mk.nextFloat(); System.out.print("Enter marks of AI:"); AI = mk.nextFloat(); // Calculation of total marks and percentage obtained in 5 subjects t_marks = FLAT + COA + Networking + Python + AI; percent = (t_marks / 500.0) * 100; // display the results System.out.println("Total marks obtained in 5 different subjects ="+t_marks); System.out.println("Percentage obtained in these 5 subjects = "+percent); } }
输出
Input the marks of five subjects Enter marks of FLAT:98 Enter marks of COA:56 Enter marks of Networking:67 Enter marks of Python:89 Enter marks of AI:78 Total marks obtained in 5 different subjects =388.0 Percentage obtained in these 5 subjects = 77.60000000000001
在上面的Java程序中,从用户那里输入了5个不同科目的成绩,分别是 FLAT,COA,Networking,Python 和 AI。
标记作为用户的输入并存储在浮点数据类型的变量中。此外,这些科目获得的总分是通过将每个科目的分数相加来计算的,并存储在名为t_marks的变量中。
最后,程序会显示指定科目的总分及其百分比。
本文阐明了计算总分及其百分比的两种方法。文章首先讨论了学期百分比和总分。第一种方法讨论的是不接受用户输入的方法,而第二种方法则将分数的值作为用户的输入,计算并显示分数的总和和百分比。
以上是Java程序示例,用于计算总分和百分比的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

Java 8引入了Stream API,提供了一种强大且表达力丰富的处理数据集合的方式。然而,使用Stream时,一个常见问题是:如何从forEach操作中中断或返回? 传统循环允许提前中断或返回,但Stream的forEach方法并不直接支持这种方式。本文将解释原因,并探讨在Stream处理系统中实现提前终止的替代方法。 延伸阅读: Java Stream API改进 理解Stream forEach forEach方法是一个终端操作,它对Stream中的每个元素执行一个操作。它的设计意图是处

Java是热门编程语言,适合初学者和经验丰富的开发者学习。本教程从基础概念出发,逐步深入讲解高级主题。安装Java开发工具包后,可通过创建简单的“Hello,World!”程序实践编程。理解代码后,使用命令提示符编译并运行程序,控制台上将输出“Hello,World!”。学习Java开启了编程之旅,随着掌握程度加深,可创建更复杂的应用程序。
