0

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?

vineeth sivan
  • 510
  • 3
  • 18
  • Please read "[How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve)". You show a lot of code that has nothing to do with your question. – Andreas Feb 10 '16 at 05:23

1 Answers1

0

This is what would suggest. You can add an if statement to the loop that searches through the test file and if the conditions evaluate to true then you print that line in the text file.Then break out of the loop.

for (i = 0; i < n && scan.hasNext(); i++)

{

      if(scan.hasNext() == x)

{

System.out.println("(x,y) values are:"+ points[i].x + "\t" +points[i].y);

break;

}

}