为什么不是“int total =(mark / overall)* 100;”工作?当我输入25和50时它应该是50%,它计算25/50 * 100.但它显示0%而不是很奇怪。有什么建议??
public class MarksCalculator {
private static Scanner kb = new Scanner(System.in);
public static void main (String[]args) {
int mark = 0, overall = 0;
//System.out.print("Hello Deepo! To calculate the marks enter value (percantage) of the task: ");
//int weight = kb.nextInt();
System.out.print("Enter your marks for this Task/Assesment/Test: ");
mark = kb.nextInt();
System.out.print("What was this mark out of: ");
overall = kb.nextInt();
int total = (mark/overall) * 100;
System.out.println("You have scored " + total + "% with this assesment.");
}
}
答案 0 :(得分:3)
答案 1 :(得分:2)
如果你想避免浮点(但为什么?),你也可以重新排序因子:
int total = 100 * mark / overall;