周宝贝周宝贝吧 关注:5贴子:281
  • 1回复贴,共1
Problem statement
Write a program which reads in a number n and prints an n by n square with a cross pattern using the characters 'A' and 'h' exactly as shown.
Input
The input consists of a single positive integer n. The value of n will be small -- less than 256.
Output
Print the required n square on n lines using only the characters 'A' and 'h' so that a cross appears in the result.
Specifically the desired pattern is formed by two diagonal lines reaching from the two top corners to the opposite corners on the bottom.
See the sample input for an example.
Sample
Input
5
Sample
Output
AhhhA
hAhAh
hhAhh
hAhAh
AhhhA
NOTE CAREFULLY: Pay close attention to spaces and punctuation. Your program must produce exactly the required output (nothing extra) and DETAILS COUNT. The sample input and output are often suggestive. Your program will likely be tested with DIFFERENT data.)


1楼2015-11-05 14:32回复
    import java.util.Scanner;
    class bbbb
    {
    public static void main(String[] args)
    {
    Scanner fred = new Scanner( System.in );
    int n = fred.nextInt();
    for (int i = 0; i < n ; i++)
    {
    for (int j = 0; j < n; j++)
    {
    if ( (i == j) ||( (i + j == n - 1) ) )
    {
    System.out.print("X");
    }
    else
    {
    System.out.print("T");
    };
    };
    System.out.println("");
    }


    2楼2015-11-05 15:04
    回复