黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 學習攻略 技術分享,Java函數練習題及答案

技術分享,Java函數練習題及答案

更新時間:2020-06-11 11:25:03 來源:動力節點 瀏覽2354次

練習一:函數式接口

1.定義一個函數式接口CurrentTimePrinter,其中抽象方法void printCurrentTime(),使用注解 FunctionalInterface

2.在測試類中定義static void showLongTime(CurrentTimePrinter timePrinter),該方法的預期行為是使用timePrinter打印系統當前毫秒值

3.測試showLongTime(),通過lambda表達式完成需求

答案

TimePrinter接口:

FunctionalInterface
public interface CurrentTimePrinter
{

void printCurrenTime();
}

測試類:

public class Test01{
public static void main(String[]args){
showLongTime(()->System.out.println(System.currentTimeMillis()));
}

public static void showLongTime(CurrentTimePrinter timePrinter){
timePrinter.printCurrentTime();
}
}

練習二:函數式接口

1.定義一個函數式接口IntCalc,其中抽象方法int calc(int a,int b),使用注解 FunctionalInterface

2.在測試類中定義static void getProduct(int a,int b,IntCalc calc),該方法的預期行為是使用calc得到a和b的乘積并打印結果

3.測試getProduct(),通過lambda表達式完成需求

答案

IntCalc接口:

FunctionalInterface
public interface IntCalc{
int calc(int a,int b);
}

測試類:

public class Test02{
public static void main(String[]args){
getProduct(2,3,(a,b)->a*b);
}

public static void getProduct(int a,int b,IntCalc intCalc){
int product=intCalc.calc(a,b);
System.out.println(product);
}
}

練習三:靜態方法引用

1.定義一個函數式接口NumberToString,其中抽象方法String convert(int num),使用注解 FunctionalInterface

2.在測試類中定義static void decToHex(int num,NumberToString nts),該方法的預期行為是使用nts將一個十進制整數轉換成十六進制表示的字符串,tips:已知該行為與Integer類中的toHexString方法一致

3.測試decToHex(),使用方法引用完成需求

答案

NumberToString接口:

FunctionalInterface
public interface NumberToString{
String convert(int num);
}

測試類:

public class Test03{
public static void main(String[]args){
decToHex(999,Integer::toHexString);
}

public static void decToHex(int num,NumberToString nts){
String convert=nts.convert(num);
System.out.println(convert);
}
}

以上就是動力節點java培訓機構的小編針對“技術分享,Java函數練習題及答案”的內容進行的回答,希望對大家有所幫助,如有疑問,請在線咨詢,有專業老師隨時為你服務。

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 亚洲福利 影院 | 国产视频麻豆 | 国产色综合久久无码有码 | 天天摸夜夜摸成人免费视频 | 一区二区在线视频观看 | 男女视频在线 | 777毛片| 婷婷丁香色 | 国产高清狼人香蕉在线观看 | 欧美成人全部费免网站 | 黄网站在线观看高清免费 | 中文字幕在线观看免费视频 | 欧美在线成人午夜影视 | 日韩区欧美区 | 国产成人精品在视频 | 77se77亚洲欧美在线大屁股 | 国产高清免费的视频 | 一个人看的www视频免费 | 日本大黄网站 | 欧美黄网址 | 美国一级做a一级爱视频 | 国产一级高清视频免费看 | 欧美精品一区二区三区在线播放 | 亚洲高清综合 | 黄色片免费在线观看 | 天天操天天干天天干 | 成人精品一区久久久久 | 成人午夜视频在线播放 | 欧美一级高清片欧美国产欧美 | 高清欧美一级在线观看 | 午夜视频在线观看视频 | 国产精品视频免费播放 | 伊人激情在线 | 日日添日日摸 | 欧美日韩影视 | 99一级毛片 | 26uuu欧美日韩国产 | 亚洲国产日韩精品 | 中文字幕影院 | 一级片黄色一级片 | 国产成人一区在线播放 |