#What do operators use?

1 messages · Page 1 of 1 (latest)

fallen waveBOT
#

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

fallen waveBOT
#

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.

tepid arrow
#

Here is a better screenshot

normal heath
#

If you are going to use mathematical operations with the numbers, you should not use string. Int is for whole number, numbers that has not decimal part like 1, 65, 998. If you are dealing with decimal number, number like 1.55, 99.69 then use double.

#

Since it is a calculator, and you can get decimal numbers from divison, you should use double

tepid arrow
#

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on token "+", Expression expected after this token

I get this error when I try to run the program, I dont know what +, -, *, / get assigned as

empty ice
#

I think you want to store the operator like +, -, *, /

tepid arrow
#

Yea, I want to store them

empty ice
#

that, you need to declare the operator as string

#

not, int

tepid arrow
#

oh okay, thank you

empty ice
#

then you can use switch statement, or if condition

#

i bet you know how to read the input?

tepid arrow
#

yea

empty ice
#

brilliant, good luck Dukehello

#

note that

#

when you compare string

#

you do not use "==" in java

#

do you learn that in class, don't you?

tepid arrow
#

nope, didnt know that

empty ice
#

in java, you use .equals(xxx)

fallen waveBOT
#

TL;DR: Comparing some types with ==, (especially String references) can have confusing results. Always use a.equals(b) for Strings.

A variable's type is either a primitive or a reference:

  • Primitive values are, for example, 0 or 1 for int, true or false for boolean, 'a' or '*' for char...
  • Reference values are either null or a reference to an object. eg The value of s in String s = "Foo" is reference to a String object, not the object itself.

Using == compares the values of two variables. If two reference values are the same, they refer to the same object or are both null.

Using a.equals(b) calls a method on a that compares its contents to the object referenced by b. You are asking if the two objects are alike.

Imagine you know the following three people:

  • jane
  • bob
  • Bob's identical twin brother michael, also known as mike.

The following are examples of using == and .equals:

  • jane == bob - false. They are not the same person
  • jane.equals(bob) - false. They are not alike
  • bob == michael - false. They are not the same person
  • bob.equals(michael) - true. They are alike
  • michael == mike - true. They are the same person

Strings are special in Java and, because of this, comparing references to Strings can be surprising. Though there are rare cases where it is useful and necessary to use == with String references, you should almost always be using .equals(Object) to compare the Strings of two references. For two strings a and b use a.eqauls(b) rather than a == b.

Note: a.equals(b) is intended to see if the two objects referenced by a and b are alike. How alike they must be depends on the implementation of equals for the class of a. The default implementation of equals, for a class extending Object, has the same behaviour as using ==.

tepid arrow
#

ahh I get it now

empty ice
#

good luck, have fun

tepid arrow
#

wait that fixed the next problem I was gonna have LOL

#

thank you

#

alright im gonna close this now

empty ice
tepid arrow
#

(I dont know how to close it)

empty ice
#

/help-thread close I guess

#

they've update the command, so you probably can see the prompt