• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to set input user eqaul to a subtraction problem?  RSS feed

 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to set the input from the user be equal to the subtraction problem.


I am currently at that but It just print "C" I only want it  to print C if usernum is equal to number1 -number2 (BTW number 1 and 2 are math. Random) Thanks!
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

BTW, have you learned how to use the "if" conditionals yet?

Henry
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks for the reply I have learned a little and this is what I have now. Let me know what  I have wrong. Thanks!
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, your pseudo code is this...

Junaid Mahmud wrote:I am currently at that but It just print "C" I only want it  to ... print C if usernum is equal to number1 -number2 ... (BTW number 1 and 2 are math. Random) Thanks!


Can you convert that to a Java instruction?

Henry
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really I am having trouble. This is the updated code. Thanks
 
Norm Radder
Rancher
Posts: 2240
28
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove the semi-colon at the end of line 22.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the duplicate thread, Junaid Mahmud wrote:I am trying to code so that usernum2 does not equal (number2 - number1). I know that != is used for Booleans. I am completely stuck. Thanks
. . . . I know that != is used for Booleans. . . .
I think you know that incorrectly. You sho‍uld avoid != for booleans as much as possible; if you need to know whether two booleans are different use the exclusive‑or operator ^. If you use == or != on Booleans, that tests for object identity not equality of content, and you will not necessarily get the answer you want.You will get different results if you use booleans; change the B at the start of each line to b and see what happens. As for != and == on booleans, that is still fraught will problems; Java® does not support an iff operator. Avoid !=It is worse to write != true or != false, which are difficult to read and poor style. Use
if (b) ...
or
if (!b) ...
instead. Because of the risk of writing = by mistake, == true or == false are worse still, and very error‑prone.

What is wrong with the operators shown in this part of the Java™ Tutorials? What do you mean about setting user input equal? Do you mean to test that is your arithmetic reads 9 − 4 you are having 5 entered?

This is the closed duplicate thread.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!