我在 java 中设计了不同的模式,然后我希望所有模式都打印在一条水平线上。我的程序以垂直线显示输出。这是我的代码:
package demo;
public class PatternDemo {
public static void main( String[] args ) throws InterruptedException {
int n = 5;
for ( int i = 0; i < n; i++ ) {
for ( int j = 0; j < n; j++ ) {
if ( i == 0 || j == 0 || i == n / 2 || (i <= n / 2 && j == n - 1)
|| i == n - 2 && j == n - 3 || i == n - 1 && j == n - 1 ) {
System.out.print( "* " );
} else {
System.out.print( " " );
}
}
System.out.println( );
}
for ( int i = 0; i < n; i++ ) {
for ( int j = 0; j < n; j++ ) {
if ( i == 0 || j == 0 || j == n - 1 || i == n / 2 ) {
System.out.print( "* " );
} else {
System.out.print( " " );
}
}
System.out.println( );
}
}
}
繁花如伊
胡说叔叔
小怪兽爱吃肉
相关分类