+ 1
Can anyone can help me with this...
class Program { public static void main(String[] args) { int maxmarks=500; double term1=412.0d; double term2=423.0d; double term3=430.0d; double pt1=(30/100)*term1; double pt2=(30/100)*term2; double pt3=(40/100)*term3; double totalmarks=pt1+pt2+pt3; double totalper=totalmarks/maxmarks*100; System.out.println("Total percentage of the student is "+totalper+"%" } } //Why the result is coming 0.0%? //pls help
1 Answer
+ 5
Integer Division.
30 divided by 100 is 0.3 normally but in java when you use 30/100 it returns only the integer part which is the 0 and discards the remainder so instead you want to use the modulus sign % which returns the remainder.
class Program
{
public static void main(String[] args)
{
int maxmarks=500;
double term1=412.0d;
double term2=423.0f;
double term3=430.0f;
double pt1=(30%100)*term1;
double pt2=(30%100)*term2;
double pt3=(40%100)*term3;
double totalmarks=pt1+pt2+pt3;
double totalper=totalmarks/maxmarks*100;
System.out.println("Total percentage of the student is "+totalper+"%");
}
}
//Why the result is coming 0.0%?
//pls help