Created
July 28, 2019 13:42
-
-
Save hrsvrdhn/fdffb662089a398eeb4229d487f60d0e to your computer and use it in GitHub Desktop.
Minmax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class minmax | |
{ | |
int n; | |
void input() { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
this.n = Integer.parseInt(br.readLine()); | |
} | |
int findSum() { | |
int max_value = 1, min_value = 9; | |
while(this.n > 0) { | |
int digit = this.n % 10; | |
if(digit < min_value) | |
min_value = digit; | |
if(digit > max_value) | |
max_value = digit; | |
} | |
int ans = max_value + min_value; | |
return ans; | |
} | |
public static void main(String args[]) { | |
minmax obj = new minmax(); | |
obj.input(); | |
int ans = obj.findSum(); | |
System.out.println("The sum of maximum and minimum digits of a given number is " + ans); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment