Skip to content

Commit f6c616c

Browse files
authored
Update JSoupValidateAndSum.java
1 parent 0d94f8b commit f6c616c

1 file changed

Lines changed: 21 additions & 27 deletions

File tree

JSoupValidateAndSum.java

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,46 @@
1-
package com.zetcode;
21

32
import org.jsoup.Jsoup;
43
import org.jsoup.nodes.Document;
54

6-
import java.io.IOException;
7-
85
// the program reads data from a web page, validates it and
96
// calculates sum from them
107
// uses custom validation method
118

12-
public class JSoupValidateAndSum {
13-
14-
public static void main(String[] args) throws IOException {
15-
16-
String url = "http://test.webcode.me/data.txt";
9+
void main(String[] args) throws IOException {
1710

18-
Document doc = Jsoup.connect(url).get();
11+
String url = "https://test.webcode.me/data.txt";
1912

20-
String content = doc.body().text();
21-
System.out.println(content);
13+
Document doc = Jsoup.connect(url).get();
2214

23-
String[] vals = content.split(",\\s+");
15+
String content = doc.body().text();
16+
System.out.println(content);
2417

25-
int sum = 0;
18+
String[] vals = content.split(",\\s+");
2619

27-
for (String val : vals) {
20+
int sum = 0;
2821

29-
if (isNumeric(val)) {
22+
for (String val : vals) {
3023

31-
sum += Integer.parseInt(val);
32-
}
33-
}
24+
if (isNumeric(val)) {
3425

35-
System.out.println(sum);
26+
sum += Integer.parseInt(val);
3627
}
28+
}
3729

38-
public static boolean isNumeric(String val) {
30+
System.out.println(sum);
31+
}
3932

40-
int len = val.length();
33+
boolean isNumeric(String val) {
4134

42-
for (int i = 0; i < len; i++) {
35+
int len = val.length();
4336

44-
if (!Character.isDigit(val.charAt(i))) {
37+
for (int i = 0; i < len; i++) {
4538

46-
return false;
47-
}
48-
}
39+
if (!Character.isDigit(val.charAt(i))) {
4940

50-
return true;
41+
return false;
5142
}
43+
}
44+
45+
return true;
5246
}

0 commit comments

Comments
 (0)