My input is like this. I have to read more than 5000 values from a file including negative and float and double values also that values are input to my jarvis march agorithm.
1
2
6
-5
8
7.32
2
3
8
-3.32
9
1.25
7
3
Code:
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();
}
}
How to get n value from file?