Write a Dart Program that takes a number as input and then displays a rectangle of 3 columns wide and 5 rows tall using that digit

Enter a number: 5
Expected Output:
555
5 5
5 5
5 5
555

Code:

import 'dart:io';

void main() {
  stdout.write('Input Number : ');
  int x = int.parse(stdin.readLineSync());

  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 3; j++) {
      if (j % 2 == 0 || i == 0 || i == 4) {
        stdout.write(x);
      } else {
        stdout.write(' ');
      }
    }
    print('');
  }
}


Output:


Comments

Popular posts from this blog

Write a Dart program to convert from celsius degrees to Kelvin and Fahrenheit.

Write a Dart program to create a new string from a given string (length 1 or more ) with the first character added at the front and back.