Discuss / Java / 作业

作业

Topic source

import java.util.Scanner;

public class Score {

public static void main(String[] atgs) {

Scanner scanner = new Scanner(System.in); // 创建Scanner对象

        System.out.print("Input your second last score: "); // 打印提示

        int score1 = scanner.nextInt(); // 读取一行输入并获取字符串

        System.out.print("Input your last score: "); // 打印提示

        int score2 = scanner.nextInt(); // 读取一行输入并获取整数

        float percentage = (float)(score2 - score1) / score1 * 100;

        System.out.println(percentage);

        System.out.printf("Your current score is lower than the last time %.2f%%\n", percentage); // 格式化输出

}

}


  • 1

Reply