AF
Home
Tag
Submit Notes
Ask Anything
Login
Subscribe Us
A
ny
F
orum
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.
Follow @anyforumin
corejava-programming: Age Difference
Given the age of 10 couples(husband and wife), print Number of years of age difference for all the 10 people.
Input Specification:
First 10 inputs contain the ages of all husbands And the next 10 are the ages of all wives
Output Specification:
Output should be exactly 10 lines giving the number of years of the age difference between them.
Note: output is a positive integer
Sample Input:
50 40 53 24 78 99 63 22 55 15 43 39 55 24 56 89 60 18 56 25
Sample Output:
7
1
2
0
22
10
3
4
1
10
corejava x 353
programming x 169
Posted On :
2017-02-01 23:56:33.0
Aarti Kumar
59
0
0
4
Answers
import java.util.Scanner;
public class CouplesAgeCalculator {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String ages[]=input.nextLine().split(" ");
for(int i=0;i<=9;i++){
System.out.println(Math.abs(Integer.parseInt(ages[i])-Integer.parseInt(ages[i+10])));
}
}
}
Posted On :
2017-02-03 00:22:03
Satisfied :
1 Yes
3 No
Rishi Kumar
523
1882
41268
Reply This Thread
4
Post Answer
Please Login First to Post Answer:
Login
Answer:
anyforum.in