Question

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);
Was it helpful?

Solution

Is that what you looking for?:

double d = (double)(a) + ((double)(b/c))/(e);

OTHER TIPS

double d = a + (double)(e / b);
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 :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top