Discuss / Java / 自做版

自做版

Topic source

import java.util.Scanner;

/**

 * 输入上次考试成绩(int)和本次考试成绩(int),然后输出成绩提高的百分比,保留两位小数位(例如,21.75%)

 */

public class 自做 {

public static void main(String[] args) {

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

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

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

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

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

        float percent= ((float)score-(float)prev)/(float)score*100;

System.out.printf("you have imrpoved by %.2f%%", percent);

}

}


  • 1

Reply