Q:

How to print a char a certain number of times?

I am trying to create code that takes a user-inputted number, and store it as an int. I then print out 'int' number of lines, with 'int' number of 'char' in each of them. So say for example, the inputted number was 3, it would then output
XXX
XXX
XXX

However, when I try to do this, it just gives me the number it would calculate of the ASCII number * the inputted number. This is my current code:
public static void main(String[] args) {
    Scanner kb = new Scanner (System.in);
    System.out.println("Please enter a number:");
    int number = kb.nextInt();
    kb.close();
    char letter = 'X';
    int sqnumber = number * number;
    for (int i = 0; i < number; i++) {
            System.out.println (letter * number);
    }
}

However, this just gives me:
Please enter a number:
3
264
264
264

A:

You need to have nested for loops and you are not using char Xcorrectly.
Try this
public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        System.out.println("Please enter a number:");
        int number = kb.nextInt();
        kb.close();
        char letter = 'X';
        int sqnumber = number * number;
        for (int i = 0; i < number; i++) {
            for (int j = 0; j < number; j++) {
                System.out.print(letter);
            }
            System.out.println();
        }
    }

Output
Please enter a number:
4
XXXX
XXXX
XXXX
XXXX

