Scanner sc=new Scanner(System.in);
int n=sc.nextInt()
String s=new StringBuilder().append(n).reverse().toString();
System.out.println(Integer.parseInt(s));
I am trying to reverse a number but when I try to give negative numbers for example if I give input as -124 it gives me NumberFormatException. Can anyone tell me why this is happening?