+ 1

Hello y'all, Please what's wrong with this code?

https://code.sololearn.com/c9xAks03Ny0Z/?ref=app

29th Dec 2017, 2:13 PM
success daudu
success daudu - avatar
3 Answers
+ 10
Almost every line has an error, please go through the Java course again. It's a request. BTW - Here's the working replacement: import java.util.Scanner; public class Program { public static void main(String[] args) { System.out.println ("Hello, Welcome to Dr. Nerds calculator, input + for addition and - for subtraction"); Scanner scanner = new Scanner(System.in); char user = scanner.next().charAt(0); int result = 0; if (user == '+') { System.out.println("Please, input numbers to add"); int num1 = scanner.nextInt(); int num2 = scanner.nextInt(); result = num1 + num2; System.out.println("Your answer is " + result); } else if (user == '-') { System.out.println("Please, input numbers to subtract"); int s1 = scanner.nextInt(); int s2 = scanner.nextInt(); result = s1 - s2; System.out.println("Your answer is " + result); } else { System.out.println("You inputed a wrong option!"); } } }
29th Dec 2017, 2:20 PM
Dev
Dev - avatar
+ 7
@success: No problem, happy to help in any way I can :)
29th Dec 2017, 2:23 PM
Dev
Dev - avatar
+ 4
Thanks mate... Am still learning...
29th Dec 2017, 2:21 PM
success daudu
success daudu - avatar