How to make the division of 2 ints produce a float instead of another int?

后端 未结 9 1126
天命终不由人
天命终不由人 2020-11-22 08:24

In another Bruce Eckels exercise in calculating velocity, v = s / t where s and t are integers. How do I make it so the division cranks out a float?

         


        
9条回答
  •  孤城傲影
    2020-11-22 08:56

    Try this:

    class CalcV 
    {
          float v;
          float calcV(int s, int t)
          {
              float value1=s;
              float value2=t;
              v = value1 / value2;
              return v;
          } //end calcV
    }
    

提交回复
热议问题