+ 1

Java Error Please help my friends !!!

My editor is showing my code as can't be compiled. Please check the error in my code. import java.util.Scanner; class Find{ public static void main(String[]args){ Scanner query = new Scanner(System.in); int inp1= query.nextInt(); int inp2=query.nextInt(); int add = inp1 + inp2; System.out.println("Sum = "+ add); if(inp1>inp2){ System.out.printlns("Substraction = "+inp1 - inp2); }else{ System.out.println("Substraction = "+inp2 - inp1); }

4th Feb 2018, 3:07 PM
A ARORA
A ARORA - avatar
3 Respostas
+ 9
// missing brackets, parentheses. // syntax errors import java.util.Scanner; import java.lang.Math; class Find { public static void main(String[] args){ Scanner query = new Scanner(System.in); int inp1= query.nextInt(); int inp2= query.nextInt(); int add = inp1 + inp2; System.out.println("Sum = "+ add); System.out.println("Substraction = "+ Math.abs(inp1 - inp2)); } }
4th Feb 2018, 3:15 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Try parantheses with your operations. In every if block, you have a string to which you add an Integer. Fine. Then you perform a mathematical operation on the string. That doesn't work.
4th Feb 2018, 3:12 PM
1of3
1of3 - avatar
0
Thank you so very much everyone.
4th Feb 2018, 5:54 PM
A ARORA
A ARORA - avatar