"int total = (mark/overall) * 100;"이 아닌 이유는 무엇입니까? 일? 25/50을 입력 한 후 25/50 * 100을 계산 한 후 50 %가되어야합니다. 그러나 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.");
}
}
25/50 때문에이 int' 계산'0입니다. 한 쪽을 두 배로 캐스팅합니다 (다른 쪽은 암시 적으로 캐스팅됩니다). – Maroun