-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathAndmeuuring.java
48 lines (47 loc) · 1.12 KB
/
Andmeuuring.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.io.*;
import java.net.*;
public class Andmeuuring{
String asukoht;
public Andmeuuring(String asukoht){
this.asukoht=asukoht;
}
BufferedReader kysiLugeja(){
try{
if(asukoht.startsWith("http://")){
return new BufferedReader(new InputStreamReader(
new URL(asukoht).openConnection().getInputStream()));
}
else {
return new BufferedReader(new FileReader(asukoht));
}
} catch(Exception ex){
return null;
}
}
public double maksimum(int tulbanr) throws IOException{
BufferedReader lugeja=kysiLugeja();
boolean alustatud=false;
String rida=lugeja.readLine(); //pealkirjarida
rida=lugeja.readLine();
int puuduvaid=0;
double maxtemp=0;
while(rida!=null){
String[] m=rida.split(",");
try{
double temperatuur=Double.parseDouble(m[tulbanr]);
if(alustatud){
if(temperatuur>maxtemp){maxtemp=temperatuur;}
} else {
maxtemp=temperatuur;
alustatud=true;
}
} catch(Exception veaandmed){
puuduvaid++;
}
rida=lugeja.readLine();
}
if(puuduvaid>0){System.err.println("Puuudu "+puuduvaid);}
lugeja.close();
return maxtemp;
}
}