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 4 of 4

Thread: Can't adjust width of the X.

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't adjust width of the X.

    i had to draw an X shape with x's, i managed to do it but the problem is that i cant seem to figure out how to adjust the width of the "X". Can anyone help?
    public class JavaApplication9
    {
    public static void printX(int x)
        {
            char[] chars = new char[x];
            for (int i = 0; i < x; i++) 
                {
                    chars[i] = 'x';
                    chars[x - 1 - i] = 'x';
                    for (int j = 0; j < x; j++) {
                        if (j == i || j == (x - 1 - i)) {
                            continue;
                        }
                        chars[j] = ' ';
                    }
                    System.out.println(new String(chars));
                }
     
            }
        }
    __________________________________________________ __________________________________________________ _____________________________
    Current Output:
    when i run the program is run i can enter the height(in this case 6)
    x    x
     x  x 
      xx  
      xx  
     x  x 
    x    x
    __________________________________________________ __________________________________________________ _______________________________
    I also want to adjust the width. For example:
    xxx    xxx
     xxx  xxx
      xxxxxx
       xxxx
       xxxx
      xxxxxx  
     xxx  xxx
    xxx    xxx
    (something like that)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Cant adjust width of the X

    Please post the program's current output and add an example of how you want to change the output and what you want it to look like.

    Also Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.


    Also post code for testing the method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cant adjust width of the X

    I tried to show all that you asked for, was it enough or do you need more detail?

    If you do, here are the directions i was given:

    Write a program, which can print out a letter 'X'. You, the programmer, choose the various parameters of 'X' (how tall and wide it is,
    how wide its 'legs' are.) (In other words, these parameters are fixed within the program. Your 'X' will
    be the same width and height each time your program is run.) Start this program on a new page.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can't adjust width of the X.

    Look at what prints on each line and find a relationship between what is on a line and what line is being printed.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to programmatically set combobox width?
    By stab in forum AWT / Java Swing
    Replies: 1
    Last Post: June 3rd, 2011, 03:59 PM
  2. [SOLVED] JTables: How do I adjust row order as I drag columns?
    By assel in forum AWT / Java Swing
    Replies: 3
    Last Post: December 7th, 2010, 04:51 PM
  3. how to adjust the size on a graphic component
    By Khoatic in forum AWT / Java Swing
    Replies: 8
    Last Post: November 19th, 2010, 11:28 PM
  4. JTable is not fit to the screen width.
    By rajakumarjk in forum AWT / Java Swing
    Replies: 2
    Last Post: October 12th, 2010, 10:13 AM
  5. JButton Width & Height
    By Howdy_McGee in forum Java Theory & Questions
    Replies: 4
    Last Post: May 22nd, 2010, 07:12 AM