Results 1 to 20 of 20
Like Tree1Likes
  • 1 Post By bulbulalbar

Thread: I Need Help!!

  1. #1
    bulbulalbar is offline Member
    Join Date
    Apr 2014
    Posts
    8
    Rep Power
    0

    Question I Need Help!!

    Hello Guys
    I'm New To Java
    And I have this java course
    with a program that I can't figure a solution for it
    the program is simple just allow the user to input a number Greater than zero and Less Than 9999
    after that the out put should be the number that user input but in a draw
    I just did it using while loop and nested if statements
    but the problem is that each number shows in a single line

    for example
    the input is 1111
    in my code the out put is this
    |
    |
    |

    |
    |
    |


    |
    |
    |

    |
    |
    |


    |
    |
    |

    |
    |
    |
    seems like I solved the half of the homework
    but the problem is I want all the numbers to be at the same line
    if input is 1111
    the out put should be :
    | | |
    | | |
    | | |

    | | |
    | | |
    | | |


    I wish someone could help me with it
    i'm gonna share my code with you so you can figure out a solution


    import javax.swing.*;
    class test
    {
    public static void main(String args[])
    {
    int x=Integer.parseInt(JOptionPane.showInputDialog("En ter the number you want to diplay"));


    String line = System.getProperty("line.separator");
    while(x>0)
    {
    int y=x%10;
    if (y==1)
    {
    System.out.print(" |"+line+" |"+line+" |"+line+" "+line+" |"+line+" |"+line+" |"+line);
    }

    if (y==2)
    {
    System.out.print(" ---"+line+" |"+line+" |"+line+" ---"+line+" |"+line+" |"+line+" ---");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" | ");
    System.out.println(" | ");
    System.out.println(" ---");
    }
    if (y==3)
    {
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    }
    if (y==4)
    {
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    }
    if (y==5)
    {
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    }
    if (y==6)
    {
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    }
    if (y==7)
    {
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    }
    if (y==8)
    {
    System.out.println(" ---");
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    }
    if (y==9)
    {
    System.out.println(" ---");
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");

    }
    x=x/10;



    }
    }
    }


    wish you all a good day

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: I Need Help!!

    Hi,

    if you want the items on the same line then you should remove the line separator.

    If y = 1 you do:
    Java Code:
    System.out.print(" |"+line+" |"+line+" |"+line+" "+line+" |"+line+" |"+line+" |"+line);
    where line is the newline item. So if you want it to be on one line, you could simply do a
    Java Code:
    System.out.println(" | | |  | | |");
    With kind regards,

    Konrad

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,984
    Rep Power
    9

    Default Re: I Need Help!!

    Please use more informative post titles as well as the code tags when posting code.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    bulbulalbar is offline Member
    Join Date
    Apr 2014
    Posts
    8
    Rep Power
    0

    Default Re: I Need Help!!

    Quote Originally Posted by kneitzel View Post
    Hi,

    if you want the items on the same line then you should remove the line separator.

    If y = 1 you do:
    Java Code:
    System.out.print(" |"+line+" |"+line+" |"+line+" "+line+" |"+line+" |"+line+" |"+line);
    where line is the newline item. So if you want it to be on one line, you could simply do a
    Java Code:
    System.out.println(" | | |  | | |");
    With kind regards,

    Konrad
    1 should be displayed like this
    |
    |
    |

    |
    |
    |

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

    Default Re: I Need Help!!

    if input is 1111
    the out put should be :
    | | |
    | | |
    | | |

    | | |
    | | |
    | | |
    Is that output for the input of 1111 or for 111?
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    bulbulalbar is offline Member
    Join Date
    Apr 2014
    Posts
    8
    Rep Power
    0

    Default Re: I Need Help!!

    The Output for 1111
    is
    | | | |
    | | | |
    | | | |

    | | | |
    | | | |
    | | | |

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

    Default Re: I Need Help!!

    It looks like the code needs to generate a character ('|' or ???) in the current row for each digit in the number.
    If there are 4 digits, then there are 4 columns of characters.

    How many rows of characters are to be printed?
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    bulbulalbar is offline Member
    Join Date
    Apr 2014
    Posts
    8
    Rep Power
    0

    Default Re: I Need Help!!

    Quote Originally Posted by Norm View Post
    It looks like the code needs to generate a character ('|' or ???) in the current row for each digit in the number.
    If there are 4 digits, then there are 4 columns of characters.

    How many rows of characters are to be printed?
    Man The Input Is Always A Number From 4 digits
    Num>=0&Num<=9999
    Thats The Condition
    and the output for each number is
    |
    |
    |

    |
    |
    |
    ---
    |
    |
    ---
    |
    |
    ---
    And Same For all But All Output Should Be In One Line

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

    Default Re: I Need Help!!

    All Output Should Be In One Line
    I don't understand how it is all on one line. The sample in post#6 is on 7 lines.
    Please explain and show an example where All Output ... In One Line
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: I Need Help!!

    Hmm,

    So you have 7 lines and for each character you want to have characters in it?

    If that is correct, then you could build up the lines first, e.g 7 strings that you append to.
    Once you are done you print the lines.

    Or you have nested loops:
    Outer loop has lines
    Inner loop goes through the characters
    That way you can write line by line.
    To avoid to many if. Statements / case statements, I would create an 2d array which contains the characters to print so a characterToPrint[line][number] would give the characters that should be printed ....

    Konrad

  11. #11
    bulbulalbar is offline Member
    Join Date
    Apr 2014
    Posts
    8
    Rep Power
    0

    Default Drawing numbers,Help

    Hello Guys
    I'm New To Java
    And I have this java course
    with a program that I can't figure a solution for it
    the program is simple just allow the user to input a number Greater than zero and Less Than 9999
    after that the out put should be the number that user input but in a draw
    I just did it using while loop and nested if statements
    but the problem is that each number shows in a single line

    for example
    the input is 1111
    in my code the out put is this
    |
    |
    |

    |
    |
    |


    |
    |
    |

    |
    |
    |


    |
    |
    |

    |
    |
    |
    seems like I solved the half of the homework
    but the problem is I want all the numbers to be at the same line
    if input is 1111
    the out put should be :
    | | |
    | | |
    | | |

    | | |
    | | |
    | | |


    The Number That user did input should display in seven segment using 7 lines for each number and all numbers on same lines

    I wish someone could help me with it
    i'm gonna share my code with you so you can figure out a solution


    import javax.swing.*;
    class test
    {
    public static void main(String args[])
    {
    int x=Integer.parseInt(JOptionPane.showInputDialog("En ter the number you want to diplay"));


    String line = System.getProperty("line.separator");
    while(x>0)
    {
    int y=x%10;
    if (y==1)
    {
    System.out.print(" |"+line+" |"+line+" |"+line+" "+line+" |"+line+" |"+line+" |"+line);
    }

    if (y==2)
    {
    System.out.print(" ---"+line+" |"+line+" |"+line+" ---"+line+" |"+line+" |"+line+" ---");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" | ");
    System.out.println(" | ");
    System.out.println(" ---");
    }
    if (y==3)
    {
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    }
    if (y==4)
    {
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    }
    if (y==5)
    {
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    }
    if (y==6)
    {
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    }
    if (y==7)
    {
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    }
    if (y==8)
    {
    System.out.println(" ---");
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    }
    if (y==9)
    {
    System.out.println(" ---");
    System.out.println(" | |");
    System.out.println(" | |");
    System.out.println(" ---");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");

    }
    x=x/10;



    }
    }
    }


    wish you all a good day

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

    Default Re: I Need Help!!

    Same questions - merged.

    Please answer the questions that were asked about what the output is supposed to look like.
    Also look at a solution proposed in post#10
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    bulbulalbar is offline Member
    Join Date
    Apr 2014
    Posts
    8
    Rep Power
    0

    Default Re: I Need Help!!

    Quote Originally Posted by Norm View Post
    Same questions - merged.

    Please answer the questions that were asked about what the output is supposed to look like.
    Also look at a solution proposed in post#10
    Man I Didn't understand the solution in post#10
    And The Output should be the number drawn like seven segment with 7 lines for each number
    If SomeOne Can Share A Code With Me That Would Be Amazing
    ...

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

    Default Re: I Need Help!!

    We still don't know what you are trying to do. It looks like the objective is to print 7 lines of some char like a '|' or a space with the content of each column in those 7 rows determined by a digit.

    What are the valid digits?
    What are the 7 values for each digit?

    Can you give an example for 325?
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    bulbulalbar is offline Member
    Join Date
    Apr 2014
    Posts
    8
    Rep Power
    0

    Default Re: I Need Help!!

    Quote Originally Posted by Norm View Post
    We still don't know what you are trying to do. It looks like the objective is to print 7 lines of some char like a '|' or a space with the content of each column in those 7 rows determined by a digit.

    What are the valid digits?
    What are the 7 values for each digit?

    Can you give an example for 325?
    the user is allowed to input a number greater than 0 and less than 9999
    so
    if the input is 2101
    the output should look this way
    I Need Help!!-10306772_10202499330019125_1890934150504271956_n.jpg
    Last edited by bulbulalbar; 04-26-2014 at 06:57 PM.
    Hieu App likes this.

  16. #16
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: I Need Help!!

    Hi,

    I understood, that you need to write multiple numbers where each number is printed over multiple lines.
    But your java application only writes line bye line. So you have 2 possibilities:

    1) You can write each line into a puffer. That way you can append to each puffer till you are done with all numbers and then print the results you got.

    2) You can write your code in a way that you write line by line. So you have to write the first line with all parts first, then the 2nd line and so on.

    But you could simply take paper and pen and play with the algorithm yourself. But regarding output, all you can do is:
    - append to current line
    - go to next line
    So with that limitation: What would you do? You can either find a way to write all line by line (my 2nd suggestion) or use another piece of paper where you write all parts you want to write and then at the end simply copy that to your "output" piece of paper.

    With kind regards,

    Konrad

  17. #17
    bulbulalbar is offline Member
    Join Date
    Apr 2014
    Posts
    8
    Rep Power
    0

    Default Re: I Need Help!!

    Quote Originally Posted by kneitzel View Post
    Hi,

    I understood, that you need to write multiple numbers where each number is printed over multiple lines.
    But your java application only writes line bye line. So you have 2 possibilities:

    1) You can write each line into a puffer. That way you can append to each puffer till you are done with all numbers and then print the results you got.

    2) You can write your code in a way that you write line by line. So you have to write the first line with all parts first, then the 2nd line and so on.

    But you could simply take paper and pen and play with the algorithm yourself. But regarding output, all you can do is:
    - append to current line
    - go to next line
    So with that limitation: What would you do? You can either find a way to write all line by line (my 2nd suggestion) or use another piece of paper where you write all parts you want to write and then at the end simply copy that to your "output" piece of paper.

    With kind regards,

    Konrad
    Thank You Konard But I Actually Can't Translate Your Possibilities into a code
    can you do it for me

  18. #18
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,648
    Blog Entries
    7
    Rep Power
    21

    Default Re: I Need Help!!

    btw, that triangle in reply #15 is not made by the code shown in the image.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  19. #19
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: I Need Help!!

    Hi,

    where is your problem regarding the translation? Just focus on one of both possible solutions and try it. Maybe the first solution is the easier one.
    So instead of using System.out.print statements, you append to variables.
    So you need a variable for each of the planed 7 lines.
    And string concatenation could be done with the + operation.
    And when you did that, you just need to print all these variables.

    Right now I do not see, where you have problem right now. I divided it down to multiple steps right now - could you point out, where you see a problem?

    Konrad

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

    Default Re: I Need Help!!

    The pattern you showed for 1111 was misleading because all were 1s and all took only one column.
    Now I see that each digit has its own width.
    The pattern for each number must be stored in an array of 7 elements(1 for each row). For the initial testing I suggest only building and storing 3 digits. Then put each of the 3 (in the future 10) arrays into a two dimension array such that the digit-1 is the index into the 2D array that will access the one dimension arrray that holds the 7 rows of char for that digit. For example: 3-1 =2 the index for the third number in the 2D array.
    If you don't understand my response, don't ignore it, ask a question.

Tags for this Thread

Posting Permissions

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