本文介绍了树功能日常锻炼:范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是迟来的Java解决方案。


import java.util.List;

import java.util.ArrayList;

import java.lang.Math;


class math {

public static List range(double n){

返回范围(1,n,1);

}


公共静态列表范围(双n,双m){

返回范围(n,m,1);

}


公共静态列表范围(双iMin,双iMax,双iStep){<

List ll = new ArrayList();

if(iMin< = iMax&& iStep> 0){

for(int i = 0; i< = Math.floor((iMax-iMin)/ iStep); i ++){

ll.add(new Double(iMin + i * iStep));

}

返回ll;

}

if(iMin> = iMax&& iStep< 0) {

for(int i = 0; i< = Math.floor((iMin-iMax)/ - iStep); i ++){

ll.add(new双倍(iMin + i * iStep));

}

返回ll;

}

//需要在这里提出例外

返回ll;

}

}


类范围{

public static void main(String [] arg){

System.out.println(math.range(5));

System.out.println(math .range(5,10));

System.out.println(math.range(5,7,0.3));

System.out.println(math .range(5,-4,-2));

}

}


Perl&此处存档的Python版本:



Xah


a ??

亲爱的功能编程人员,


i运行服务称为a-python-a-day和a-java-a-day,每天我都会给你一个提示或者提示这些语言的代码片段,对我来说也是一种方式


来学习这些语言。


我一直在运行这个perl -py $ a $ day个月的邮件列表,并在这里累积了一个相当大的教程:



在未来的日子里,我''将开始翻译一整套

树处理函数。这些函数总是将树作为

输入(任意嵌套列表)并始终返回一个明确的

结构的列表。它们共同构成了一个特定的功能性编程

范例。请参阅此页面以获取完整的文档

now:
ica_dir / Matica.html


我们每天都会花20分钟左右享受这些


小练习。如果过去的经验是一个很好的指示,那么我认为在一两个月内我们将构建一套完整的

函数来操纵tress,用Python语言和Java和

Perl。 (Perl集已经写好了)


我总是对LISP和Haskell语言感兴趣,但从来没有认真学过它们。我希望你能够在这些语言或学习者中使用这些语言或学习者,每天15分钟和我一起练习

练习作为学习语言或功能的有趣例程/>
编程。


我特别对功能程序员对这些

主题的日常讨论非常感兴趣,以及看到scsh和Haskell中这样一套完整的

代码。 (Common Lisp或其他功能语言

当然是受欢迎的)


?* Xah

?* x ... @ xahlee.org

a ??

Here''s the belated Java solution.

import java.util.List;
import java.util.ArrayList;
import java.lang.Math;

class math {
public static List range(double n) {
return range(1,n,1);
}

public static List range(double n, double m) {
return range(n,m,1);
}

public static List range(double iMin, double iMax, double iStep) {
List ll = new ArrayList();
if (iMin <= iMax && iStep > 0) {
for (int i=0; i <= Math.floor((iMax-iMin)/iStep); i++) {
ll.add(new Double(iMin+i*iStep));
}
return ll;
}
if (iMin >= iMax && iStep < 0) {
for (int i=0; i <= Math.floor((iMin-iMax)/-iStep); i++) {
ll.add(new Double(iMin+i*iStep));
}
return ll;
}
// need to raise exception here
return ll;
}
}

class Range {
public static void main(String[] arg) {
System.out.println(math.range(5));
System.out.println(math.range(5,10));
System.out.println(math.range(5,7, 0.3));
System.out.println(math.range(5,-4, -2));
}
}

Perl & Python versions archived here:
http://xahlee.org/tree/tree.html

Xah
xa*@xahlee.org
a?? http://xahlee.org/
Dear functional programers,

i run services called a-python-a-day and a-java-a-day, where each day i

give a tip or snippet of code in these languages, also as a way for me

to learn these languages.

I''ve been running this perl-python a-day mailing list for several
months, and have accumulated a sizable tutorial here:
http://xahlee.org/perl-python/python.html

In the coming days, i''ll be starting to translate a complete set of
tree processing functions. These functions, always takes a tree as
input (arbitrary nested list) and always returns a list of a definite
structure. Together, they form a particular functional programing
paradigm. See this page for the complete documentation as it exists
now:
http://xahlee.org/PerlMathemat ica_dir/Matica.html

As usuall, each day we will be spending about 20 minutes enjoying these

little exercises. If past experience is a good indication, then i
presume that in a month or two we will have built a complete set of
functions that manipulates tress, in languages Python and Java and
Perl. (the Perl set is already written)

I''m always interested in LISP and Haskell languages, but never
seriously learned them. I''m hoping that you functional programers in
these languages or learners, join me in these 15 minutes daily
exercises as a fun routine to learn languages or functional
programing.

I''m in particular very interested in the daily discussions of these
topics by functional programers, as well seeing such set of complete
code in scsh and Haskell. (Common Lisp or other functional languages
are always welcome of course)

?* Xah
?* x...@xahlee.org
a?? http://xahlee.org/

推荐答案




这篇关于树功能日常锻炼:范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:28