Hello in my code Im trying to get the users input for my div

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<Integer> aL = new LinkedList<Integer>();

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<Integer> aL = new LinkedList<Integer>();

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<Integer> aL = new LinkedList<Integer>();

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> aL = new LinkedList<Double>();

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;
}

}

Solution

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<Integer> aL = new LinkedList<Integer>();

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<Integer> aL = new LinkedList<Integer>();

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<Integer> aL = new LinkedList<Integer>();

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> aL = new LinkedList<Double>();

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 = (int)(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;

}

}


================================================================================
Use this it works,


Your result variable is of type int and you are assigning it to doubles.



It will always print interger values


Like if division returns 0.5 it will print 0

1.5 will be printed as 1 because your result is Integer..





Thanks, for any doubts feel free to ask me.

Hello in my code I\'m trying to get the users input for my division rule to work, however I keep getting this error, \
Hello in my code I\'m trying to get the users input for my division rule to work, however I keep getting this error, \
Hello in my code I\'m trying to get the users input for my division rule to work, however I keep getting this error, \
Hello in my code I\'m trying to get the users input for my division rule to work, however I keep getting this error, \
Hello in my code I\'m trying to get the users input for my division rule to work, however I keep getting this error, \
Hello in my code I\'m trying to get the users input for my division rule to work, however I keep getting this error, \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site