AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
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 ?.



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 168
Posted On : 2017-02-01 23:56:33.0
profile Aarti Kumar - anyforum.in Aarti Kumar
5900
up-rate
4
down-rate

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
profile Rishi Kumar - anyforum.in Rishi Kumar
523188222688
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in