Wednesday 13 September 2017

Bhuvan love to play with numbers- Program in Java

Bhuvan loves to play with numbers.his friend Arya gives him two numbers to add.arya is suffering from dysgraphia sometimes writes 6 as 5 and vice versa, given two numbers x,y find the maximum and minimum sum Arya could possibly get.


Input Specification: The first and only line of input contains two digit positive integers A and B

Output Specification: In a single line of output, print two space separated integers, minimum and maximum sum Arya could get. For any Wrong input Print ´A´ or ´B´ is an Invalid Input.


Write a program in Java to find the minimum and maximum sum?


Example:


              Suppose we have two number as 5 and 6. Then Bhuvan writes 5 as 6 and 6 as 5.and we have to the minimum and maximum sum from two numbers.

5+5=10 //minimum
6+6=12 //maximum

Program in java:-

import java.util.Scanner;

public class Sum{
 
public static void main(String[] args) {
System.out.println("Enter the numbers A and B separated by space");
Scanner input=new Scanner(System.in);
Integer a=input.nextInt();
Integer b=input.nextInt();
if(a<0){
System.out.println(a+" is an invalid input ");
}
else if(b<0){
System.out.println(b+" is an invalid input ");
}
else{ 
a=Integer.parseInt(Integer.toString(a).replaceAll("6","5"));
b=Integer.parseInt(Integer.toString(b).replaceAll("6", "5"));
System.out.print((a+b)+" ");
a=Integer.parseInt(Integer.toString(a).replaceAll("5", "6"));
b=Integer.parseInt(Integer.toString(b).replaceAll("5", "6"));
System.out.print((a+b));
}


INPUT:
45  56

OUTPUT:
100   102          

No comments:

Post a Comment