#im trying to make a simple calculator
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
Don't worry, everyone faces challenges when learning a new programming language. I'm here to help you with your calculator program in Java. Can you please provide more details about the specific problem you are facing?
package main;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//create stuff
Scanner scanner = new Scanner(System.in);
//variable crap
System.out.print("Enter a number: ");
long numberInputOne = scanner.nextLong();
System.out.print("Enter another number: ");
long numberInputTwo = scanner.nextLong();
System.out.print("Enter your math symbol: ");
String symbol = scanner.next();
char first = symbol.charAt(0);
System.out.println(numberInputOne + first + numberInputTwo);
//actual stuff
}
}
Detected code, here are some useful tools:
package main;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//create stuff
Scanner scanner = new Scanner(System.in);
//variable crap
System.out.print("Enter a number: ");
long numberInputOne = scanner.nextLong();
System.out.print("Enter another number: ");
long numberInputTwo = scanner.nextLong();
System.out.print("Enter your math symbol: ");
String symbol = scanner.next();
char first = symbol.charAt(0);
System.out.println(numberInputOne + first + numberInputTwo);
//actual stuff
}
}
I test your codes with input '1 + 1', then get a InputMismatchException.
That's the behavior I expect no doubt.
⬆️
Seeing your code, what you are saying doesn't make sense, the code is asking to first enter an Integer then a second Integer then an operator
The output 45 does make sense though for what your code is now.
You do numberInput1 + first + numberInput2.
That results in 1 + '+' + 1.
You are doing an expression, so Java tries to convert the character to an integer value.
The character index for the plus sign is 43
So that makes 1 + 43 + 1, which is 45
Not at all 
thanks, i did a bit more googling and i figured out that i needed to use switch() and cases to actually add, subtract, divide, or multiply the numbers. Thanks!