Who wants some easy Duke Points

this is copied directly from the Sun's Java Tutorial (see link):

http://java.sun.com/docs/books/tutorial/essential/io/formatting.html

is it a typo?

public class Root2 {

public static void main(String[] args) {

int i = 2;

double r = Math.sqrt(i);

System.out.format("The square root of %d is %f.%n", i,r);

}

}

the line starting with System.out..... gives me the error:

The method format(String, Object[]) in the type PrintStream is not applicable for the arguments

(String, int, double)

I changed things around and got it to work as follows:

public class Root2 {

public static void main(String[] args) {

int i = 7;

double r = Math.sqrt(i);

Number[] n = {Integer.valueOf(i),Double.valueOf(r)};

System.out.format("The square root of %d is %f.%n", n);

}

}

[886 byte] By [thousea] at [2007-11-27 9:53:56]
# 1
The original code compiles fine for me.
kajbja at 2007-7-13 0:23:17 > top of Java-index,Java Essentials,New To Java...
# 2
It is working fine in Java 1.5.0. No error messages.You may be using older version of java. Check it once.
polimetlaa at 2007-7-13 0:23:17 > top of Java-index,Java Essentials,New To Java...
# 3
actually - I started using java 1.6.0_02 and I also tried 1.5.0_11 - I'm using eclipse 3.2.2
thousea at 2007-7-13 0:23:17 > top of Java-index,Java Essentials,New To Java...
# 4
> actually - I started using java 1.6.0_02 and I also> tried 1.5.0_11 - I'm using eclipse 3.2.2Check your compiler settings.
kajbja at 2007-7-13 0:23:17 > top of Java-index,Java Essentials,New To Java...
# 5
Nice - they were set to 1.4 - I changed them to 6.0 and the error went away. Thanks.
thousea at 2007-7-13 0:23:17 > top of Java-index,Java Essentials,New To Java...
# 6

> > actually - I started using java 1.6.0_02 and I

> also

> > tried 1.5.0_11 - I'm using eclipse 3.2.2

>

> Check your compiler settings.

as kajbj said, check thecompiler settings, chances are they are set to compile to a compliance level of 1.4 (Window -> Java -> Compiler -> Compiler compliance level)

~Tim

EDIT: Too late again. **** I am slow this AM :)

SomeoneElsea at 2007-7-13 0:23:17 > top of Java-index,Java Essentials,New To Java...
# 7
> Nice - they were set to 1.4 - I changed them to 6.0> and the error went away. Thanks.Np
kajbja at 2007-7-13 0:23:17 > top of Java-index,Java Essentials,New To Java...