我越来越非法开始表达
问题描述:
import java.util.Scanner;
//trying to print pyramid shape
class try
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the number of lines:");
int n=in.nextInt();
for(int i=n;i>0;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print(" ");
}
j=n-(i-1);
for(int k=0;k<j;k++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
但iam无法打印解决。我越来越非法开始表达
答
这是您的问题的解决方案。
import java.util.Scanner;
//trying to print pyramid shape
class Try
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the number of lines:");
int n=in.nextInt();
int i,j;
for(i=n;i>0;i--)
{
for(j=1;j<=i;j++)
{
System.out.print(" ");
}
j=n-(i-1);
for(int k=0;k<j;k++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
它有编译问题!将'j'移动到循环中 – VinayVeluri 2014-09-12 10:15:01
编译器会告诉你有问题的行。请告诉我们。 – 2014-09-12 10:15:09