+ 1
Hello y'all, Please what's wrong with this code?
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!");
}
}
}
+ 7
@success: No problem, happy to help in any way I can :)
+ 4
Thanks mate...
Am still learning...