Task
Were given three real numbers x, y, z. Check whether the inequality [latex]x < y < z[/latex] is correct. If it is correct, show as an result the word «true». If it is not correct, show as an result the word «false».
Tests
Input | Output |
8 9 25 | true |
9 25 8 | false |
8 25 9 | false |
9 8 25 | false |
25 8 9 | false |
25 9 8 | false |
Solution
With «if» statement:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import java.util.*; 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(); int z = s.nextInt(); if(x < y && y < z) { System.out.println("true"); } else { System.out.println("false"); } s.close(); } } |
Code refactoring
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import java.util.*; 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(); int z = s.nextInt(); System.out.println(x < y && y < z? true : false); s.close(); } } |