0

The output should be

AAAAAAAAA
BBBBBBBBB
CCCCCCCCC
DDDDDDDDD
EEEEEEEEE
FFFFFFFFF
GGGGGGGGG
HHHHHHHHH
IIIIIIIII
JJJJJJJJJ

My code is this:

        char let = 65;
        for (int i = 0;i < 10; i ++)
        {
           for (int x = 0; x < 10; x ++)
           {
              System.out.print(let);
           }
           System.out.println();
           let++;
        }

I know im very close but what am i doing wrong i cant seem to figure this out

skjcyber
  • 5,759
  • 12
  • 40
  • 60

2 Answers2

0

Edit: Sorry my mistake. Your code should work.

Troubleshoot
  • 1,816
  • 1
  • 12
  • 19
  • Why would you need to cast a char to a char? Java already knows that `let` is a `char`, no need to cast it. – bfontaine Oct 05 '13 at 23:16
  • Oh yeah I just looked it up and you're correct. I assumed it was displaying the values as ints since it does the same with other primitives. – Troubleshoot Oct 05 '13 at 23:19
0

You could do it this way (while + for loop):

public static void main(String[] args) {

    final int RECT_WIDTH  =  9;
    final int RECT_HEIGHT = 10;

    final char BEGIN_LETTER = 'A';

    char currentLetter = BEGIN_LETTER;
    while ((currentLetter - BEGIN_LETTER) < RECT_HEIGHT) {
        for (int column=0; column<RECT_WIDTH; column++) {
            System.out.print(currentLetter);
        }
        System.out.println();
        currentLetter++;
    }

}

There are many more ways to achieve the same result. 2 nested for loops, ...

MrSnrub
  • 1,123
  • 1
  • 11
  • 19