Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 906
  • Last Modified:

Android : find smallest difference

Hi Experts,
Could you please help me to resolve following problem.
The file football.txt contains the results from the English Premier League for 2001/2. The columns labeled ‘F’ and ‘A’ contain the total number of goals scored for and against each team in that season (so Arsenal scored 79 goals against opponents, and had 36 goals scored against them). Need a java program to print the name of the team with the smallest difference in ‘for’ and ‘against’ goals.
My main objective of this question is to identify the activities we will be able to write the code and demonstrate some of the practices and techniques that we would use in best practices under industry. I'm mainly be looking for the thought process and how we can complete this task. But points goes to the first/best post.

Thanks a lot Experts.
Dushan De Silva
Dushan De Silva
2 Solutions
Julian HansenCommented:
So if I understand your question correctly you need something like this
current = 10000
team = ""
while (line=read_line_from_file) {
   cells = split(line)
   diff = cell(7) - cell(9) // SEE first point - might need to take absolute value here
   if (diff < current) {
      current = diff
      team = cell(2)
output "Team " + team + " With " + current + " goal diff"

Open in new window

1. It was not clear if you want the difference only to be positive where teams have scored more goals than have been scored against them - or are you only interested in absolute goal difference so if team A scores 80 for and has 60 against diff is 20 but Team B scores 60 and has 65 agains diff is 5 - which team is the one you want?
Hamidreza VakilianSenior iOS DeveloperCommented:
Apart the platform you are on; You have to parse the text to read each value associated with each team. You may choose to use simple string handling functions approach but you will have a hard time though. I suggest you to use regular expressions which allows you to parse such texts and detects the elements of the text based on your expression. Regular Expression is well integrated in almost all programmings.

Regex in java:
Dushan De SilvaTechnology ArchitectAuthor Commented:
Thanks a lot!

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now