import java.util.*;
public class SoSanh {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
if( a > b ) System.out.print("1");
else if ( a < b ) System.out.print("-1");
else System.out.print(0);
}
}
How can I make this as small as possible. It had to be like 1-2 lines of code ( not including import,public class and main method )
This is not a homework, I learn Java through books and assignment on the internet. I just want to know if it can gets any shorter. It’s not about Speed u guys are misunderstanding.
Sorry I’m very bad at English.
p/s : now I cannot ask any question 🙁 there is only 1 more question I am facing with.
Almost correct:
“Almost” due to possible integer overlow. Also your longer code might actually be faster (
signum()operaton on floating-point numbers), not to mention more readable.