编写一个Java程序,使用for循环打印右箭头数字图案。
import java.util.Scanner;
public class RightArrowNumber1 {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, j;
System.out.print("Enter Right Arrow Number Pattern Rows = ");
int rows = sc.nextInt();
System.out.println("Printing Right Arrow Numbers Pattern");
for (i = 1 ; i <= rows; i++ )
{
for (j = 1 ; j <= rows; j++ )
{
if(j < i) {
System.out.print(" ");
}
else {
System.out.print(j);
}
}
System.out.println();
}
for (i = 1 ; i < rows; i++ )
{
for (j = 1 ; j <= rows; j++ )
{
if(j < rows - i) {
System.out.print(" ");
}
else {
System.out.print(j);
}
}
System.out.println();
}
}
}

这是使用while循环显示右箭头数字图案的另一种Java程序写法Java程序。
import java.util.Scanner;
public class RightArrowNumber2 {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int i, j, k;
System.out.print("Enter Right Arrow Number Pattern Rows = ");
int rows = sc.nextInt();
System.out.println("Printing Right Arrow Numbers Pattern");
for (i = 1 ; i <= rows; i++ )
{
for (j = 1 ; j < i; j++ )
{
System.out.print(" ");
}
for (k = i ; k <= rows; k++ )
{
System.out.print(k);
}
System.out.println();
}
for (i = rows - 1 ; i >= 1; i-- )
{
for (j = 1 ; j < i; j++ )
{
System.out.print(" ");
}
for (k = i ; k <= rows; k++ )
{
System.out.print(k);
}
System.out.println();
}
}
}
Enter Right Arrow Number Pattern Rows = 9
Printing Right Arrow Numbers Pattern
123456789
23456789
3456789
456789
56789
6789
789
89
9
89
789
6789
56789
456789
3456789
23456789
123456789