Skip to content

Instantly share code, notes, and snippets.

@hrsvrdhn
Created July 28, 2019 13:42
Show Gist options
  • Save hrsvrdhn/fdffb662089a398eeb4229d487f60d0e to your computer and use it in GitHub Desktop.
Save hrsvrdhn/fdffb662089a398eeb4229d487f60d0e to your computer and use it in GitHub Desktop.
Minmax
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