-
Notifications
You must be signed in to change notification settings - Fork 0
/
BestRep.java
executable file
·31 lines (26 loc) · 1004 Bytes
/
BestRep.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.lang.Integer;
public class BestRep {
public static void main(String []args) throws Exception {
String line;
JSONParser parser=new JSONParser();
int maxRep = -1;
// open the file
FileInputStream fis = new FileInputStream("users.json");
BufferedReader br = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8")));
while ((line = br.readLine()) != null) {
JSONObject user=(JSONObject)parser.parse(line);
int rep = Integer.parseInt((String)user.get("Reputation"));
if(rep>maxRep) {
maxRep = rep;
System.out.println(user);
}
}
System.out.println("The user with the highest reputation has "+maxRep+" points.");
}
}