• 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

Returning a boolean value

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing an applet that recieves two inputs and calculates whether the second input is a multiple of the first and then returns a value of true or false. So I believe I would have to convert my mod result from int to boolean and that is what I can't seem to figure out. or should I just return a string of "true" or "false" here is the code I have written so far but I am still changing it now.

Thank you Ryan Perlman
(edited by Cindy to format code)
[This message has been edited by Cindy Glass (edited November 05, 2001).]
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just change your method signature to public boolean modulo()
Bosun
 
Ryan Perlman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what to use to convert boolean to string from my modulo method.
resultField.setText(Boolean.toString(???); mod or result but neither work cannot resolve symbol. Stuck
Ryan
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to take in a int value and return a boolean you set it up like:

Then to use it
String answer = Boolean(modulo(number2 % number1)).toString();
This feeds the remainder into the modulo method as an int and returns a boolean, converts to a Boolean and gets the String value of it.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String.valueOf((num1 % num2) == 0); // KISF (Keep it simple, friend )

------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh all right!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic