⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 question7.java

📁 java课程的资料以及实验的代码
💻 JAVA
字号:
class Question7
{
	static double doMultiplication(double first,long times) //recursive method to compute first*times, times is long integer
	{
		if (times==0) return(0);
		else if (times==1) return(first);
		else return(first+doMultiplication(first,times-1));
	};
	
	static double result(double first,double second) //compute first*second
	{
		double r=0,se=second;
		long y;
		double factor=1.0;
		y=(long)se;
		se=(se-y)*10;
		r+=doMultiplication(first,y); //compute first* the number before decimal point
		while (se!=0) // obtain each digit after possible decimal point
		{
			y=(long)se;
			factor*=10.0;
			r+=doMultiplication(first,y)/factor;
			se=(se-y)*10;
		}
		return(r);
	};
	
	public static void main(String args[])
	{
		if (args.length<2) 
		{
			System.out.println("invalid number of parameters\n");
			System.exit(1);
		};
		double first,second;
		first=Double.parseDouble(args[0]); //obtain 2 parameters
		second=Double.parseDouble(args[1]);
		byte signed=1; // determine whether result is positive or negative
		if ((first<0)&&(second>=0)) 
		{
			signed=-1;
			first=-first;
		}
		else if ((first>=0)&&(second<0))
		{
			signed=-1;
			second=-second;
		}
		else if ((first<0)&&(second<0))
		{
			first=-first;
			second=-second;
		};
		double r=result(first,second);
		if (signed==-1) r=-r;
		System.out.println("the result is:"+r+"\n");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -