Sorry guys, in my last post was a typing error.
The class definition should be this way
> *
>
> public
> **class* Percent{
>
> *public* *static* *void* main(String[] args) {
>
> Percentls =
> *new* Percent();
>
> System.
> *out*.println(ls.np(10F));
>
> }
>
> *public* *float* np(*float* l){
>
> *return* l/100;
>
> }
>
> }
>
> result : 0.1
>
> 2009/3/13 Anton Shaykin <[email protected]>
>
>
>> You have to clearly distinguish integral and floating point types. In
>> first case, whatever operation you're trying to perform the result
>> will always be an integer, like the following code will print out to
>> the console 1, because i is declared as an integer:
>>
>> int i = 3;
>> i/=2;
>> System.out.println(i);
>>
>> And if you use double type instead of int (and double is floating-
>> point type), then running the following code:
>>
>> double i = 3;
>> i/=2;
>> System.out.println(i);
>>
>> you will get 1.5! So try learning the basics of Java, before dealing
>> with this course.
>> Good luck!
>>
>>
>> On Mar 13, 8:52 pm, Jerrold <[email protected]> wrote:
>> > This is great!! i tried it and it work. Just a thought... why is it
>> > that when directly dividing 10/100 the result is 0 but if in a method
>> > it generated the correct answer?
>> >
>> > Thank you very much!!!
>> > Dave
>> >
>> > On Mar 14, 1:09 am, Shawn Ayromloo <[email protected]> wrote:
>> >
>> > > You can divide a number by a larger number - in non-integer mode.
>> > > Is this what you need?public class Rate {
>> > > static float rate (float percent) {
>> > > return (percent / 100);
>> > > }
>> > > public static void main(String[] args) {
>> > > System.out.println (rate (10));
>> > > System.out.println (rate (20));
>> > > }
>> > > }run:
>> > > 0.1
>> > > 0.2
>> > > BUILD SUCCESSFUL (total time: 0 seconds)
>> > >
>> >
>> >
>>
>> >>
>>
>
>
> --
> Atentamente
>
> Alfonso Bullon Vallejo
>
--
Atentamente
Alfonso Bullon Vallejo
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---