#im trying to make a simple calculator

1 messages · Page 1 of 1 (latest)

fast blaze
#

I am having trouble with a calculator (am i bad at java?)
plz help

proper meteorBOT
#

<@&987246399047479336> please have a look, thanks.

proper meteorBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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?

fast blaze
#
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
    }
}
proper meteorBOT
# fast blaze ```java package main; import java.util.Scanner; public class Main { public...

Detected code, here are some useful tools:

Formatted code
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
  }
}
fast blaze
#

The result is 45 when i input 1 + 1, why?

#

pls help

burnt yarrow
#

I test your codes with input '1 + 1', then get a InputMismatchException.
That's the behavior I expect no doubt.

dusky mural
# fast blaze pls help

⬆️
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

lime heart
#

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

fast blaze