write a program in java that consider that the age of a person is read as "10 years old in the year 1960 " , write a java method that changes the age according if the current years is 2005
Answers
Answered by
1
Consider that the age of a person is read as "10 years old in the year 1960",
Write java method that changes the age according if the current year is 2005.
class Age
{
String str;
int age,year;
int pos;
public void calculate()
{
str="10 years old in the year 1990";
pos=str.indexOf(" ");
age=Integer.parseInt(str.substring(0,pos));
pos=str.lastIndexOf(" ");
year=Integer.parseInt(str.substring(pos+1));
age=age+2010-year;
str=age + " years old in the year "+2010;
System.out.println(str);
}
public static void main(String args[])
{
Age ob=new Age();
ob.calculate();
}
}
Similar questions