import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Asterisks
{
public static void main(String[] args)
{
try
{
File dataFile = new File("Asterisks.txt"); \\ this file says "S 3"
Scanner in = new Scanner(dataFile);
String shapeType = in.next();
int Dim = in.nextInt();
if (shapeType.equals("S"))
{
for(int loop = 0; loop < 4; loop ++)
{
for (int line = 0; line < Dim; line ++)
{
for(int elt = 0; elt < Dim; elt ++)
{
System.out.println(" *");
}
System.out.println(" ");
}
}
}
}
catch (FileNotFoundException e)
{
System.out.println("Data file not found.");
}
}
}
(第一次把它放在这里,所以请在评论中写下我能做些什么来让它变得更好)所以这是我的文件,我不明白为什么这个程序不能运行。
这个文件必须打印出来
* * *
* * *
* * *
我现在得到的输出是
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Asterisks.main(Asterisks.java:15)
提前感谢您的帮助。