Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Exception in thread "main" java.util.IllegalFormatWidthException: 13

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Exception in thread "main" java.util.IllegalFormatWidthException: 13

    Hello every1,
    Im starting to self learn java from a book, now im in the middle of an exercise and i got this line "Exception in thread "main" java.util.IllegalFormatWidthException: 13" in the run window, working with netbeans 6.5.1 and this is the code:

     public class Functions {
        public static int power (int base, int n) {
        int result=1;
     
        for (int i=1 ; i<=n ; ++i)
            result = result * base;
                    return result;
     
        }
        public static void main(String[] args) {
            int res1, res2;
            System.out.printf("%-4s %-13s %-13n", "i", "power(2,i)", "power(3,i)");
            System.out.printf("%-4s %-13s %-13s%n", "-", "--------", "--------");
            for (int i=0; i<10; ++i) {
                res1 = power(2,i);
                res2 = power(3,i);
                System.out.printf("%-4d %-13d %-13d%n", i, res1, res2);
            }
     
        }
    }

    can any1 plz show me the problem ?

    Thank you very much !!
    Last edited by JavaPF; June 4th, 2009 at 10:10 AM. Reason: Please use [code] [/code] tags


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Exception in thread "main" java.util.IllegalFormatWidthException: 13

    Hello xtrive and welcome to the Java Programming Forums.

    The java.util.IllegalFormatWidthException is an unchecked exception thrown when the format width is a negative value other than -1 or is otherwise unsupported.
    The problem is here:

    System.out.printf("%-4s %-13s %-13n", "i", "power(2,i)", "power(3,i)");
    I think you have copied it incorrectly. Try this:

    System.out.printf("%-4s %-13s %-13[B]s%n[/B]", "i", "power(2,i)", "power(3,i)");
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Location
    Home-Ujjain /Job-Mumbai
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wink Re: Exception in thread "main" java.util.IllegalFormatWidthException: 13

    public static void main(String[] args) {
    try{
    int res1, res2;
    System.out.printf("i "+ " power(2,i) "+ "power(3,i) \n");
    System.out.printf("%-4s %-13s %-13s%n", "-", "--------", "--------\n");
    for (int i=0; i<10; ++i) {
    res1 = power(2,i);
    res2 = power(3,i);
    System.out.printf("%-4d %-13d %-13d%n", i, res1, res2);
    }
    }catch(Exception e) {e.printStackTrace();}
    }

    Change Your main Function by this and enjoy
    Think before copy paste
    Good Luck

Similar Threads

  1. Replies: 16
    Last Post: August 27th, 2010, 03:30 PM
  2. Replies: 3
    Last Post: April 20th, 2009, 08:35 AM
  3. [SOLVED] "GridLayout" problem in Java program
    By antitru5t in forum AWT / Java Swing
    Replies: 3
    Last Post: April 16th, 2009, 10:26 AM
  4. Books and tutorials for beginners in Java and Visual Basic
    By Professor Spider in forum The Cafe
    Replies: 5
    Last Post: April 9th, 2009, 10:57 AM