0

So I am to be making a "bit pattern that will have 7 rows. I am having trouble drawing any letters with 1's and 0's while I can only use if or else statements, parse.Int, and compareTo as the instructions say. The program needs to change every 1 to an "X" and every 0 to a space. Is there a specific way to do this? For now it just endlessly loops. Thanks for any and all help. Here is my code thus far:

public static void main(String[] args) 
{
    String r1 = ("1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0");
    String r2 = ("0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0");
    String r3 = ("0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0");
    String r4 = ("0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0");
    String r5 = ("0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0");
    String r6 = ("0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0");
    String r7 = ("0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0");

    dr(r1);
    dr(r2);
    dr(r3);
    dr(r4);
    dr(r5);
    dr(r6);
    dr(r7);
}
public static void dr(String s)
{
    int i = 0;
    while(i < 1)
    {
    String[] tokens = s.split(" ");
    if (tokens[0].compareTo("0") == 0)
        System.out.println("X");
    else if (tokens[1].compareTo("1") == 1)
        System.out.println(" ");
    }
}
4
  • 1
    why do you need any special libraries for printing 0's and 1's?? Commented Oct 25, 2015 at 1:52
  • 1
    @CrakC I dont need special libraries for that. I am to be creating a bit pattern that basically draws whatever letters I put with 1's and 0's. Commented Oct 25, 2015 at 1:53
  • Is the amount of columns fixed at 19? Commented Oct 26, 2015 at 7:27
  • The rows will be locked at 7. But no the columns are not locked. They are only "locked" by whatever letter I may type in. Commented Oct 26, 2015 at 7:27

2 Answers 2

1

The easiest way to do it in your case is something like this:

String data = "1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0";
String out = data.replaceAll("1,? ?","X").replaceAll("0,? ?", " "));
Sign up to request clarification or add additional context in comments.

3 Comments

That is certainly an awesome way! But I am unable to use any specialized library.
Specialized? replaceAll is part of String class with no additional libraries.
Sorry, I misspoke. What I was meaning is we are not allowed to use elements we have not gone over. He has yet to go over those elements, thus why I am in a predicament. The compare to and if/else statements are the only way we can do this program. It is unfortunate, but such as the way of things.
0

I will suggest that you assign each letter a value (Your bits), and then storing them in an array...

We need the code.

2 Comments

Thank you for your suggestion! I would post the code, but so far all I have is the array set and a method to pass a function through. But the problem I am fighting with is actually drawing with 1's and 0's as the logic has to be set. So no matter what letters I put in, it needs to draw at least 3 letters.
atleast 3 letters? why so??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.