subject

Write a program ThueMorse. java that takes an integer command-line argument n and prints an n-by-n pattern like the ones below. Include two space characters between each + and - character.
Have to use array and cannot call string method charAt.
Hint provided was to use boolean array of length n.
This is my current code:
public class ThueMorse {
public static void main(String[] args) {
int n = Integer. parseInt(args[0]);
String[] tm = {"0", "1"};
tm[0] = "0";
tm[1] = "1";
for (int k = 1; k <= n; k++) {
String t = tm[0];
String m = tm[1];
tm[0] += m;
tm[1] += t;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (tm[0].charAt(i) == tm[0].charAt(j))
System. out. print("+ ");
else
System. out. print("- ");
}
System. out. println();
}
}
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 05:00
Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. after the loop terminates, it prints out, on a line by itself and separated by spaces, the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even integers read, and a count of the number of odd integers read, all separated by at least one space. declare any variables that are needed. assume the availability of a variable, stdin, that references a scanner object associated with standard input. that is, stdin = new scanner(system.in); is given.
Answers: 3
question
Computers and Technology, 22.06.2019 09:50
Assume that you have an sorted array of records. assume that the length of the array (n) is known. give two different methods to search for a specific value in this array. you can use english or pseudo-code for your algorithm. what is the time complexity for each algorithm and why?
Answers: 1
question
Computers and Technology, 22.06.2019 10:40
Nims is applicable to all stakeholders with incident related responsibilities. true or false
Answers: 1
question
Computers and Technology, 22.06.2019 22:50
Which is the best minecraft server? a. mineplex b. worldonecraft c. 9b9t d. 2b2t
Answers: 2
You know the right answer?
Write a program ThueMorse. java that takes an integer command-line argument n and prints an n-by-n...
Questions
question
Mathematics, 18.10.2019 05:30
question
Mathematics, 18.10.2019 05:30
question
English, 18.10.2019 05:30
Questions on the website: 13722361