• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set input user eqaul to a subtraction problem?

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really I am having trouble. This is the updated code. Thanks
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also posted at: http://www.java-forums.org/new-java/96307-set-user-input-equal-correct.html
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remove the semi-colon at the end of line 22.
 
Marshal
Posts: 79263
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic