0
我的输入是这样的。我必须从一个文件中读取超过5000个值,包括负值和浮点值以及值,这些值也会输入到我的jarvis 3月份算法中。从文件读取整数值并直接输入到程序
1
2
6
-5
8
7.32
2
3
8
-3.32
9
1.25
7
3
代码:
public static void main(String[] args) {
Scanner scan;
try
{
FileReader fr=new FileReader("nani.txt");
int[] integers = new int [50];
int i=0;
scan=new Scanner(fr);
while(scan.hasNextInt())
{
integers[i] = scan.nextInt();
i++;
for(int item: integers) {
System.out.println(item);
}
System.out.println("Jarvis Algorithm Test\n");
int n=scan.nextInt();
System.out.println(n);
scan.useDelimiter(",|\\s*");
/** Make an object of Jarvis class **/
Point[] points = new Point[n];
System.out.println("Reading X,Y Values From File");
for (i = 0; i < n && scan.hasNext(); i++)
{
points[i] = new Point();
points[i].x = scan.nextInt();
points[i].y = scan.nextInt();
System.out.println("(x,y) values are:"+ points[i].x + "\t" +points[i].y);
}
Jarvis j = new Jarvis();
Jarvis.convexHull(points);
}
scan.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
如何从文件中获得的n值?
请阅读 “[如何创建一个最小的,完整的,并且可验证的示例](http://stackoverflow.com/help/mcve)”。你展示了很多与你的问题无关的代码。 – Andreas