This is Learn Programming through Logical Thinking Series – 3.  In this post, we are going to discuss about a problem related to Ages.

 

Question:

Five years ago the average of A,B,C,D was 45 years.  With E joining them now the average of all five becomes 49 years.  What is the age of E?

Now, shall we focus on deriving algorithm for resolving this problem?

Algorithm

  1. Get the average of 5 years before
  2. Multiply average with 4 to get the year
  3. Multiply 5&4 and add he value with total years
  4. Multiply 49 &5 get the E present age
  5. Now subtract 200 from E present age

PROGRAM

package com.java.learning;

public class AgeProblem{

public static void main(String[] args)

{

int avgOfFiveInYears =45;

int totalAge=avgOfFiveInYears*4;

int preAge=5*4;

int presentAge=totalAge+preAge;

int ePreAge=49*5;

int ePresentAge=epreAge-presentAge;

System.out.print(epresentAge);

}

}

Read These Also:

  1. Learn Programming Through Logical Thinking Series – 1

  2. Learn Programming Through Logical Thinking Series – 2