Search Results

Search found 1 results on 1 pages for 'nimitips'.

Page 1/1 | 1 

  • [Netbeans 6.9] Java MethodOverloading error with double values

    - by Nimitips
    Here is a part of my code I'm having trouble with: ===Class Overload=== public class Overload { public void testOverLoadeds() { System.out.printf("Square of integer 7 is %d\n",square(7)); System.out.printf("Square of double 7.5 is %d\n",square(7.5)); }//..end testOverloadeds public int square(int intValue) { System.out. printf("\nCalled square with int argument: %d\n",intValue); return intValue * intValue; }//..end square int public double square(double doubleValue) { System.out.printf("\nCalled square with double argument: %d\n", doubleValue); return doubleValue * doubleValue; }//..end square double }//..end class overload ===Main=== public static void main(String[] args) { Overload methodOverload = new Overload(); methodOverload.testOverLoadeds(); } It compiles with no error, however when I try to run it the output is: Called square with int argument: 7 Square of integer 7 is 49 Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3999) at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2709) at java.util.Formatter$FormatSpecifier.print(Formatter.java:2661) at java.util.Formatter.format(Formatter.java:2433) at java.io.PrintStream.format(PrintStream.java:920) at java.io.PrintStream.printf(PrintStream.java:821) at methodoverload.Overload.square(Overload.java:19) at methodoverload.Overload.testOverLoadeds(Overload.java:8) at methodoverload.Main.main(Main.java:9) Called square with double argument:Java Result: 1 What am I doing wrong? I'm on Ubuntu 10.10, Netbeans 6.9. Thanks.

    Read the article

1