Reputation: 233
So I'm trying to enhance these types to get output d = 5.5, I tried different types and what I get is 5.0 , what should I do to get correct output?
int a = 5;
int b = 4;
int c = 3;
int e = 2;
double d = (double)(a) + b/c/e;
System.out.println(d);
Upvotes: 0
Views: 59
Reputation: 39365
Is that what you looking for?:
double d = (double)(a) + ((double)(b/c))/(e);
Upvotes: 1
Reputation: 10988
double a = 5.0;
double b = 4.0;
double c = 4.0;
double e = 2.0;
double d = a + b/c/e;
System.out.println(d);
This will give 5.5 :)
Upvotes: 1