Answer the question
In order to leave comments, you need to log in
How to draw a triangle in the console?
Hello. Tell me how you can display in the console such a triangle
on the left side brought out in this way
for(var i = 0; i < width; i++){
for(var j = 0; j < height; j++){
if(i == 0 || i == height){
sim += '*';
print(sim);
}
}
}
for(var a = 0; a < width; a++){
for(var b = 0; b < height; b++){
if(a == 0 || a == width){
sim += '*';
print(sim.padLeft(height));
}
}
}
Answer the question
In order to leave comments, you need to log in
this is how I did it,
I had the task to display any number that the user enters, the floors of the tree
void main() {
buildTree();
}
void buildTree() {
print('Введите количество этажей :');
var input = stdin.readLineSync();
var inputs = int.parse(input!);
var b = "*";
var branch = [b];
void addBranch() {
final branch1 = branch[0];
if (inputs > 0) {
print(branch1.padLeft(inputs-- ));
for(int i = inputs; i > 0; i--){
var tspaces = "".padLeft( --inputs );
var tree = branch[0] += "**";
print(tspaces+tree);
}
} else {
print("!!!");
}
}
for (var br in branch) {
addBranch();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question