编写一个Java程序,使用for循环打印连续行字母的右三角形图案。
package Alphabets;
import java.util.Scanner;
public class RightTriConsecRowAlp1 {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Right Triangle of Consec Row Alphabets Rows = ");
int rows = sc.nextInt();
System.out.println("Right Triangle of Consecutive Row Alphabets Pattern");
int alphabet = 64;
for (int i = 1; i <= rows; i++)
{
int val = i;
for (int j = 1; j <= i; j++ )
{
System.out.print((char)(alphabet+ val) + " ");
val = val + rows - j;
}
System.out.println();
}
}
}

这个Java模式示例使用while循环显示每行连续字母的直角三角形。
package Alphabets;
import java.util.Scanner;
public class RightTriConsecRowAlp2 {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Right Triangle of Consecutive Row Alphabets Rows = ");
int rows = sc.nextInt();
System.out.println("Right Triangle of Consecutive Row Alphabets Pattern");
int alphabet = 64;
int val, j, i = 1;
while (i <= rows)
{
val = i;
j = 1;
while( j <= i )
{
System.out.print((char)(alphabet+ val) + " ");
val = val + rows - j;
j++;
}
System.out.println();
i++;
}
}
}
Enter Right Triangle of Consecutive Row Alphabets Rows = 8
Right Triangle of Consecutive Row Alphabets Pattern
A
B I
C J P
D K Q V
E L R W [
F M S X \ _
G N T Y ] ` b
H O U Z ^ a c d
这个Java程序使用do while循环来显示连续行字母的直角三角形图案。
package Alphabets;
import java.util.Scanner;
public class RightTriConsecRowAlp3 {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.print("Enter Right Triangle of Consecutive Row Alphabets Rows = ");
int rows = sc.nextInt();
System.out.println("Right Triangle of Consecutive Row Alphabets Pattern");
int alphabet = 64;
int val, j, i = 1;
do
{
val = i;
j = 1;
do
{
System.out.print((char)(alphabet+ val) + " ");
val = val + rows - j;
} while( ++j <= i );
System.out.println();
} while (++i <= rows);
}
}
Enter Right Triangle of Consecutive Row Alphabets Rows = 10
Right Triangle of Consecutive Row Alphabets Pattern
A
B K
C L T
D M U \
E N V ] c
F O W ^ d i
G P X _ e j n
H Q Y ` f k o r
I R Z a g l p s u
J S [ b h m q t v w