java - how to code it to get pass error in method -
java - how to code it to get pass error in method -
basically trying build calculator allow user take 1-5
options of multiplying, subtracting, multiplying, or dividing. whatever choose, inquire them come in 2
numbers after selecting function want. trying set bit calculation bit below running error here, not sure how should formatted. @ part of code receiving error.
inputoperation = myselection.selectionone().equals("5"); //this getting error "cannot convert boolean int"
the part trying insert in below code (i think):
public class selection { scanner readinput = new scanner(system.in); string selectionone() { string input; { //do loop go on run until user enters right response system.out.print("please come in number between 1 , 5, addition, s subtraction, m multiplication, or d division, or x exit: "); seek { input = readinput.nextline(); //user come in response if (input.equals("a") || input.equals("s") || input.equals("m") || input.equals("d") || input.equals("x")) { system.out.println("thank you"); break; //user entered character of a, s, m, or d } else if (integer.parseint(input) >= 1 && integer.parseint(input) <= 5) { system.out.println("thank you"); break; //user entered number between 1 , 5 } else { system.out.println("sorry, have not entered right number, please seek again."); } continue; } grab (final numberformatexception e) { system.out.println("you have entered invalid choice. seek again."); continue; // loop go on until right reply found } } while (true); homecoming input; }
.
public class answers { public float answer(int choice, float [] f){ float result = 0.00f; switch (choice){ case 1: result = f[0]+f[1]; break; case 2: result = f[0]-f[1]; break; case 3: result = f[0]*f[1]; break; case 4: result = f[0]/f[1]; break; case 5: system.out.println("you exting programme \n"); break; default: system.out.println("cannot calculate.\n entered" + choice); break; } homecoming result; } public static void main (string args[]){ int inputoperation; selection myselection = new selection(); inputoperation = myselection.selectionone().equals("5"); //this getting error "cannot convert boolean int" symbol.newsymbol("you entered selection of " + inputoperation + " successfully\n\n"); symbol.displaysymbol(); float [] myfloats = myselection.picknumbers(inputoperation); symbol.newsymbol("you entered " + myfloats[0] + " , " + myfloats[1] + " successfully\n\n") ; symbol.displaysymbol(); } }
.equals("") method homecoming boolean value.
you trying store boolean value in int variable (inputoperation).
java arrays string
Comments
Post a Comment