Question
Hello in my code I'm trying to get the users input for my division rule to work, however I keep getting this error, Exception
Hello in my code I'm trying to get the users input for my division rule to work, however I keep getting this error, "
Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from double to int
at ArithmeticOperators.Division(ArithmeticOperators.java:134) at ArithmeticOperators.main(ArithmeticOperators.java:35)"
Below is my code, can someone please tell me what is causing this error.
import java.util.*;
public class ArithmeticOperators{
public LinkedList head;
private static Scanner userChoice;
public String toString() { String result = ""; LinkedList current = head; while(current.getFirst() != null){ current = (LinkedList) current.getFirst(); } return "List: " + result; }
public static void main(String[]args){
//mC stands for Math Choice Scanner mC = new Scanner(System.in); System.out.println("Enter your choice"); System.out.println("You can add or subtract"); String choice = mC.nextLine();
if(choice.equals("add")){ Addition(result); }else if(choice.equals("minus")){ Subtraction(result2); }else if(choice.equals("multiply")){ Multiply(result3); }else if(choice.equals("divide")){ Division(result4); } System.out.println("Please choose FIVE numbers to add or subtract,"); }
public static int result; public static int result2; public static int result3; public static double result4;
public static int Addition(int list){
userChoice = new Scanner(System.in); LinkedList
int a = userChoice.nextInt(); int b = userChoice.nextInt(); int c = userChoice.nextInt(); int d = userChoice.nextInt(); int e = userChoice.nextInt();
aL.add(a); aL.add(b); aL.add(c); aL.add(d); aL.add(e); result = a + b + c + d + e; System.out.println("The elements of your list are:" + aL.toString()); System.out.println("The result of your numbers are: " + result); return result;
}
public static int Subtraction(int list){
userChoice = new Scanner(System.in); LinkedList
int a = userChoice.nextInt(); int b = userChoice.nextInt(); int c = userChoice.nextInt(); int d = userChoice.nextInt(); int e = userChoice.nextInt();
aL.add(a); aL.add(b); aL.add(c); aL.add(d); aL.add(e); result = a - b - c - d - e; System.out.println("The elements of your list are:" + aL.toString()); System.out.println("The result of your numbers are: " + result); return result2; }
public static int Multiply(int list){
userChoice = new Scanner(System.in); LinkedList
int a = userChoice.nextInt(); int b = userChoice.nextInt(); int c = userChoice.nextInt(); int d = userChoice.nextInt(); int e = userChoice.nextInt();
aL.add(a); aL.add(b); aL.add(c); aL.add(d); aL.add(e); result = a * b * c * d * e; System.out.println("The elements of your list are:" + aL.toString()); System.out.println("The result of your numbers are: " + result); return result3; }
public static double Division(double list){
userChoice = new Scanner(System.in); LinkedList
double a = userChoice.nextDouble(); double b = userChoice.nextDouble(); double c = userChoice.nextDouble(); double d = userChoice.nextDouble(); double e = userChoice.nextDouble();
aL.add(a); aL.add(b); aL.add(c); aL.add(d); aL.add(e); result = a / b / c / d / e; System.out.println("The elements of your list are:" + aL.toString()); System.out.println("The result of your numbers are: " + result); return result4; }
}
Step 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