当前输出的余数为0。示例:理论成绩50.00%,最终成绩50.0%,想要删除额外的0和50%。
输入:
double theoryGrade = (test + midterm + exam) * 100/70;
double practicalGrade = (assignment + lab) * 100/30;
double finalGrade = (lab + test + assignment + midterm + exam);
System.out.printf("Theory Grade %.2f%%%n", (theoryGrade));
System.out.printf("Practical Grade %.0f%%%n", (practicalGrade));
System.out.printf("Final Grade %.1f%%%n", (finalGrade));
当前输出:
理论等级50.00%
实用等级50%
最终等级50.0%
示例输出#2:
欢迎使用CST8215最终标记计算器
输入您的Lab标记 10:5输入您的测验/测试标记10:5输入您的 分配标记超出20:10在20中输入您的中期分数: 10
输入40:20的最终考试成绩理论等级:50%
实用等级:50%
最终成绩:50%
import java.util.Scanner;
public class Assign1 { public static void main(String args []){
Scanner input = new Scanner (System.in);
System.out.println("Welcome to the CST8215 Final Mark Calculator\n");
System.out.println("Enter your Lab mark out of 10: ");
double lab = input.nextDouble();
System.out.println("Enter your Quiz/Test mark out of 10: " );
double test = input.nextDouble();
System.out.println("Enter your Assignment mark out of 20: ");
double assignment = input.nextDouble();
System.out.println("Enter your Midterm mark out of 20: ");
double midterm = input.nextDouble();
System.out.println("Enter your Final exam mark out of 40: ");
double exam = input.nextDouble();
double theoryGrade = (test + midterm + exam) * 100/70;
double practicalGrade = (assignment + lab) * 100/30;
double finalGrade = (lab + test + assignment + midterm + exam);
System.out.printf("Theory Grade %.2f%%%n", (theoryGrade));
System.out.printf("Practical Grade %.0f%%%n", (practicalGrade));
System.out.printf("Final Grade %.1f%%%n", (finalGrade));
//此部分适用于示例输出#1,但我收到的是#0输出的#0
的余数0示例输出#1 :(红色表示用户输入的信息) 欢迎使用CST8215最终标记计算器 输入您的Lab标记10:7.5 输入您的测验/测试标记10:5 输入20:18之外的作业标记 从20:15输入您的中期商标 输入40:32的期末考试成绩 理论等级:74.29% 实用等级:85% 最终成绩:77.5%
答案 0 :(得分:0)
使用%4d而不是%.2f %%% n来解决您的问题。