【发布时间】:2016-05-20 07:57:36
【问题描述】:
我的输入是这样的。我必须从一个文件中读取超过 5000 个值,包括负值、浮点值和双精度值,这些值也被输入到我的 jarvis March 算法中。
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 值?
【问题讨论】:
-
请阅读“How to create a Minimal, Complete, and Verifiable example”。您展示了很多与您的问题无关的代码。
标签: java file java.util.scanner convex-hull