Question
Hello, in my code I'm trying to implement my scanner into my if statement so that if the user responds with add then it will
Hello, in my code I'm trying to implement my scanner into my if statement so that if the user responds with "add" then it will cause my addition method to run. However I keep getting this runtime error. "Exception in thread "main" java.lang.NullPointerException at ArithmeticOperators.main(ArithmeticOperators.java:14)
I have no idea what causing this exception and was wondering if someone could tell me. Below is a copy of my code.
import java.util.*;
public class ArithmeticOperators{
private static Scanner userChoice;
public static void main(String[]args){
System.out.println("Please choose to add, subtract,"); System.out.println("multiply, or divide!"); if(userChoice.equals("add")){ Addition(result);} else{ System.out.println("thanks for trying"); }
} public static int result; public static int Addition(int list){ userChoice = new Scanner(System.in); LinkedList
}
e eclipse ava Arithmeticop java Pse erators/src/Arithmeticoperators File Edit Source Refactor Navigate Search Project Run Window Help project eticoperators java Package Exp 19 20 public static int result; AminoAcids 21 ArithmeticOperators 22 public static int Addition (int list) 23 v deraul package 24 user Choice new Scanner (System. in 25 etioope LinkedListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started