Results 1 to 8 of 8
  1. #1
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Lightbulb java.util.UnknownFormatConversionException error

    Why do I get this error?
    Java Code:
    Exception in thread "main" java.util.UnknownFormatConversionException: Conversio
    n = '5'
            at java.util.Formatter.checkText(Formatter.java:2502)
            at java.util.Formatter.parse(Formatter.java:2484)
            at java.util.Formatter.format(Formatter.java:2413)
            at java.io.PrintStream.format(PrintStream.java:920)
            at java.io.PrintStream.printf(PrintStream.java:821)
            at Maclaurin1.main(Maclaurin1.java:55)
    Press any key to continue . . .

    All I want to do is convert a number from degrees to radians (Math.toRadians())and find the Math.sin and Math.cos of it

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default

    at Maclaurin1.main(Maclaurin1.java:55)
    Can you show the printf at line 55?

  4. #4
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Default

    Heres the snippet of the code that asks to print:
    Java Code:
    public static void main(String[] args)
     	{
    		double x;
    		x = (Math.PI)/4;
                    double  rad=0;
    		double result=0;
    		System.out.printf("Evaluate x = %1.0f",x);
    		result = sine_evaluate(x);
    		System.out.printf("%nSin Result = %5.15f",result);
    		result = cos_evaluate(x);
    		System.out.printf("%nCos Result = %5.15f%n",result);
    		rad=Math.toRadians(x);
                    result = Math.sin(rad);
                   System.out.printf("%nActual Sine Result = %5.15f%n",result); 
                   result = Math.cos(rad);
                   System.out.printf("%nActual Cos Result = %5.15f%n",result);
                
    	}

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default

    I see more than one printf.
    Which one is causing the error?

  6. #6
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Default

    The errors are coming from the last 4 lines.The rest of the functions are getting executed. Im getting results if I dont include the last 4 lines.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,587
    Rep Power
    25

    Default

    Can you post THE LINE that causes the error?
    With the error message.

    Have you tried debugging your code? Try printing the values WITHOUT formatting.
    Can the value of result be NaN?
    Last edited by Norm; 10-08-2008 at 07:27 PM.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. java.util
    By Java Tutorial in forum Java Tutorial
    Replies: 1
    Last Post: 02-07-2008, 02:46 PM
  2. Using java.util.Stack
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-20-2007, 06:17 PM
  3. Using java.util.Formatter
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-16-2007, 03:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •