How to make a loop. Request vk api in java?

Good afternoon. There's a code that sends an API request to get photographs in a particular area, and saves the resulting json file.

String key = "7075966f7075966f7075966f577018909e770757075966f2dfd2579655817dfd28d3bfd";
 String Vers = "5.103";
 System.out.println("Latitude ");
 String LATITUDE = inscaner.next();
 System.out.println("Longitude ");
 String LONGITUDE = inscaner.next();
 System.out.println("Specify a search radius (e.g. 100 meters) = ");
 String radius = inscaner.next();
 String url = "https://api.vk.com/method/photos.search?"
 + "&lat=" + LATITUDE 
 + "&long=" + LONGITUDE
 + "&count=" + count
 + "&radius=" +radius 
 + "&access_token=" + key
 + "&v=" + Vers;
try {
 URL obj = new URL(url);
 HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection.setRequestMethod("GET");

 BufferedReader in = new BufferedReader(new an InputStreamReader(connection.getInputStream()));
 String inputLine;
 StringBuffer response = new StringBuffer();

 while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
/*
System.out.println(response.toString());
*/
 try (FileWriter file = new FileWriter("response-vk.json")) {
file.write(response.toString());
 } 
}catch(Exception e){}

 }


When you get such json response structure
{"response":{"count":5365,"items":[{"id":457239398,"album_id":-7,"owner_id":515520034,"sizes":[{"type":"s","url":"https:\/\/sun9-37.userapi.com\/c858024\/v858024733\/12881f\/YmnQybQVwQw.jpg","width":42,"height":75},{"type":"m","url":"https:\/\/sun9-44.userapi.com\/c858024\/v858024733\/128820\/pP86RyrkS_M.jpg","width":73,"height":130},{"type":"x","url":"https:\/\/sun9-


Stitch count:5356 shows the number of photos in this my area. Since a single query, VK allows to 1,000 photos. I need to get all 5356 photos

But in VC is an option as offsetc (offset relative to the first found user to fetch a specific subset.)

Help get all of the photos(not just the first thousand that I receive at my request).Can't think of how to do it
April 3rd 20 at 18:27
1 answer
April 3rd 20 at 18:29
loop with integer remainder (count, 1000) +1
If I understand correctly, I need something to organize the reading count.so I don't manually enter it. And make the loop? - monroe_Aufderh commented on April 3rd 20 at 18:32
get count of first response and use safely, it is still the first iteration of a request to do anyway. do not forget to check for null - Jadyn commented on April 3rd 20 at 18:35

Find more questions by tags JavaAPIVKontakte