What is the reason for the error "The operator / is undefined for the argument" in this code?

1
 double t1 = System.currentTimeMillis();
 double t2 = System.currentTimeMillis();
System.out.print("\n Tempo Total: "+ (t2-t1)/Double.valueOf(1000)+ " segundos");

When compiling the third line, corresponding to System.out.println , gives an error:

  

Unresolved compilation problem: The operator is undefined for the   argument type (s) double, Double

    
asked by anonymous 27.08.2016 / 04:25

2 answers

4

The problem is that the compiler tool in your build string is missing at the time of # from type Double to the primitive double , which is required to enable splitting. To be more instructional, there are clear rules for unboxing and widening that you find in specialized Java SE Programmer certification books. Compiling your example directly with the Oracle compiler ( see working on Ideone ) everything worked as expected, which leads me to believe that any of your tools is causing the problem.

That said, try the following:

System.out.print("\n Tempo Total: "+ ((t2-t1)/ 1000.0d)+ " segundos");

That way you're using a literal of type double and no form of unboxing is required.

    
27.08.2016 / 15:12
0

Try closing the parenthesis one more time by having your operation isolated, like this:

double t1 = System.currentTimeMillis(); 
double t2 = System.currentTimeMillis();
System.out.print("\n Tempo Total: "+ ((t2-t1)/Double.valueOf(1000))+ " segundos
    
27.08.2016 / 13:38