本文介绍了理性数字计划问题:已解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家好!



我的问题是toDouble方法似乎不起作用 - 它打印出来:Rational.Rational@1963006a而不是double。



预先感谢您的帮助!



我的代码如下:

  package  Rational; 

class Rational {
int num;
int den;
public Rational( int num, int den){
this .num = num;
.den = den;
}

public static double toDouble(Rational result){
double result = number.num / number.den;
返回结果;
}

public static void main( String [] args){
// TODO自动生成的方法stub
Rational result = new Rational( 3 4 );

toDouble(结果);
}

}
解决方案


Hey everyone!

My issue is that the method toDouble doesn't seem to be working--it prints out as this: Rational.Rational@1963006a rather than a double.

Thanks in advance for any help!

My code is as follows:

package Rational;

class Rational {
	int num;
	int den;
        public Rational(int num, int den) {
		this.num = num;
		this.den = den;
	}

	public static double toDouble (Rational result) {
		double result = number.num/ number.den;
		return result;
	}

		public static void main(String[] args) {
		// TODO Auto-generated method stub
		Rational result = new Rational (3,4);

		toDouble(result);
	}

}
解决方案


这篇关于理性数字计划问题:已解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:38