Task. Were given two real numbers [latex]x[/latex] and [latex]y[/latex]. Find [latex]\min (x, y)[/latex].
Tests
Input | Output |
---|---|
758 843 | Maximum number is: 843 |
459 238 | Maximum number is: 459 |
Solution
With if-statement
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import java.util.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner s = new Scanner(System.in); int x = s.nextInt(); int y = s.nextInt(); if (x < y) System.out.println("Minimum number is: " + x); else System.out.println("Minimum number is: " + y); s.close(); } } |
Code refactoring
Without if-statement
1 2 3 4 5 6 7 8 9 10 11 |
import java.util.*; class Main { public static void main (String[] args) throws java.lang.Exception { Scanner s = new Scanner(System.in); int x = s.nextInt(); int y = s.nextInt(); s.close(); System.out.println("Minimum number is: " + (x < y? x : y)); } } |