我希望用户输入以下模式的行数,所以请标记我的错误。由于我是 java 初学者,所以也请给我推荐一些书。必须显示此模式
**********
*********
********
*******
******
*****
****
***
**
*
这是一个代码:
import java.util.Scanner;
class pattern{
public static void main (String agrs[]){
int n;
Scanner in =new Scanner(System.in);
System.out.println("enter the no. of rows in the pattern");
n= in.nextInt();
{
for(int i=0;i<n;i++)
{ for(int j=0; j<=i;j++)
System.out.print(" * ");
System.out.println(" ");
}}
}}
ERROR ......
enter the no. of rows in the pattern
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at pattern.main(pattern.java:8)