So I have been taking some video lessons on Java programming and after watching a video on doing a very basic calculator, as I have some good knowledge of scripting for simba bots myself I though I would give it a try and try to make it to be capable of doing more operations and not just adding.
Although I get some errors and need someone to help me out here. So if you have time I appreciate.
My code:
Code:package bucky; import java.util.Scanner; class apples{ public static void main(String args[]){ Scanner bucky = new Scanner(System.in); double num1, num2, answer; String add; String sub; int operation; add = "+"; sub = "-"; System.out.println("Choose your operation: + or - "); if (add = bucky.nextLine("+")){ operation = 1; } if (sub = bucky.nextLine()){ operation = 2; } System.out.println("Enter first number: "); num1 = bucky.nextDouble(); System.out.println("Enter second number: "); num2 = bucky.nextDouble(); if (operation == 1){ answer = num1 + num2; } if (operation == 2){ answer = num1 - num2; } System.out.println("Your answer is: " + answer); } }
Errors I got:
Code:Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method nextLine() in the type Scanner is not applicable for the arguments (String) Type mismatch: cannot convert from String to boolean at bucky.apples.main(apples.java:16)
If you are willing to help me please can you tell me what I am doing wrong, and give me some extra tips on that?
Thanks in advance!![]()




Reply With Quote










