Reputation: 113
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(" ");
}
}
Upvotes: 0
Views: 88
Reputation: 26132
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,? ?", " "));
Upvotes: 1
Reputation: 65
I will suggest that you assign each letter a value (Your bits), and then storing them in an array...
We need the code.
Upvotes: 0