\noindent \ttfamily \hlstd{}\hllin{01\ }\hlkwa{import\ }\hlstd{java}\hlopt{.}\hlstd{util}\hlopt{.}\hlstd{Scanner}\hlopt{;}\\ \hllin{02\ }\hlstd{}\hlkwa{import\ }\hlstd{java}\hlopt{.}\hlstd{util}\hlopt{.{*};}\\ \hllin{03\ }\hlstd{}\hlkwa{class\ }\hlstd{Matrix\ }\hlkwa{implements}\hlstd{\ \ }\hlkwa{}\hlstd{Iterable}\hlopt{\{}\\ \hllin{04\ }\hlstd{\ ArrayList}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{m}\hlopt{;}\\ \hllin{05\ }\hlstd{\ \\ \hllin{06\ }\ }\hlkwd{Matrix}\hlstd{}\hlopt{(}\hlstd{}\hlkwb{int\ }\hlstd{a}\hlopt{,}\hlstd{}\hlkwb{int\ }\hlstd{b}\hlopt{)\ \{}\\ \hllin{07\ }\hlstd{}\hlstd{\ \ }\hlstd{m\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$();}\\ \hllin{08\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{for}\hlstd{}\hlopt{(}\hlstd{}\hlkwb{int\ }\hlstd{i\ }\hlopt{=}\hlstd{a}\hlopt{;}\hlstd{i}\hlopt{$>$}\hlstd{}\hlnum{0}\hlstd{}\hlopt{;}\hlstd{i}\hlopt{{-}{-})\{}\\ \hllin{09\ }\hlstd{}\hlstd{\ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{h\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$();}\\ \hllin{10\ }\hlstd{}\hlstd{\ \ \ }\hlstd{System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"输入一行元素"}\hlstd{}\hlopt{+}\hlstd{b}\hlopt{+}\hlstd{}\hlstr{"个"}\hlstd{}\hlopt{);}\\ \hllin{11\ }\hlstd{}\hlstd{\ \ \ }\hlstd{Scanner\ scanner\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{}\hlkwd{Scanner}\hlstd{}\hlopt{(}\hlstd{System}\hlopt{.}\hlstd{}\hlkwa{in}\hlstd{}\hlopt{);}\\ \hllin{12\ }\hlstd{}\hlstd{\ \ \ }\hlstd{}\hlkwa{for}\hlstd{}\hlopt{(}\hlstd{}\hlkwb{int\ }\hlstd{k\ }\hlopt{=\ }\hlstd{b}\hlopt{;}\hlstd{k}\hlopt{$>$}\hlstd{}\hlnum{0}\hlstd{}\hlopt{;}\hlstd{k}\hlopt{{-}{-})\ \{}\\ \hllin{13\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{}\hlkwa{if}\hlstd{}\hlopt{(}\hlstd{scanner}\hlopt{.}\hlstd{}\hlkwd{hasNext}\hlstd{}\hlopt{())}\\ \hllin{14\ }\hlstd{}\hlstd{\ \ \ \ \ }\hlstd{h}\hlopt{.}\hlstd{}\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{scanner}\hlopt{.}\hlstd{}\hlkwd{nextInt}\hlstd{}\hlopt{());}\\ \hllin{15\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{}\hlkwa{else}\hlstd{}\hlopt{\{}\\ \hllin{16\ }\hlstd{}\hlstd{\ \ \ \ \ }\hlstd{System}\hlopt{.}\hlstd{err}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"输入元素数量不足"}\hlstd{}\hlopt{);}\\ \hllin{17\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{}\hlopt{\}}\\ \hllin{18\ }\hlstd{}\hlstd{\ \ \ }\hlstd{}\hlopt{\}}\\ \hllin{19\ }\hlstd{}\hlstd{\ \ \ }\hlstd{m}\hlopt{.}\hlstd{}\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{h}\hlopt{);}\hlstd{}\hlslc{//添加一行元素}\\ \hllin{20\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlopt{\}}\\ \hllin{21\ }\hlstd{}\hlstd{\ \ }\hlstd{\\ \hllin{22\ }\ }\hlopt{\}}\\ \hllin{23\ }\hlstd{\ }\hlkwd{Matrix}\hlstd{}\hlopt{(}\hlstd{ArrayList}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{m}\hlopt{)\ \{}\\ \hllin{24\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{this}\hlstd{}\hlopt{.}\hlstd{m\ }\hlopt{=\ }\hlstd{m}\hlopt{;}\\ \hllin{25\ }\hlstd{\ }\hlopt{\}}\\ \hllin{26\ }\hlstd{\ \\ \hllin{27\ }\ }\hlkwa{public\ }\hlstd{Iterator}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{()\ \{}\\ \hllin{28\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ }\hlstd{m}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{29\ }\hlstd{\ }\hlopt{\}}\\ \hllin{30\ }\hlstd{\ }\hlkwa{public\ }\hlstd{String\ }\hlkwd{toString}\hlstd{}\hlopt{()\ \{}\\ \hllin{31\ }\hlstd{}\hlstd{\ \ }\hlstd{Iterator\ it\ }\hlopt{=\ }\hlstd{m}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{32\ }\hlstd{}\hlstd{\ \ }\hlstd{String\ s\ }\hlopt{=\ }\hlstd{}\hlstr{""}\hlstd{}\hlopt{;}\\ \hllin{33\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{while}\hlstd{}\hlopt{(}\hlstd{it}\hlopt{.}\hlstd{}\hlkwd{hasNext}\hlstd{}\hlopt{())\{}\\ \hllin{34\ }\hlstd{}\hlstd{\ \ \ }\hlstd{s\ }\hlopt{+=\ }\hlstd{it}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{().}\hlstd{}\hlkwd{toString}\hlstd{}\hlopt{()\ +\ }\hlstd{}\hlstr{"}\hlesc{$\backslash$n}\hlstr{"}\hlstd{}\hlopt{;}\\ \hllin{35\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlopt{\}}\\ \hllin{36\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ }\hlstd{s}\hlopt{;}\\ \hllin{37\ }\hlstd{\ }\hlopt{\}}\\ \hllin{38\ }\hlstd{\ Matrix\ }\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{Matrix\ bMatrix}\hlopt{)\ \{\ }\hlstd{}\hlslc{//矩阵加法}\\ \hllin{39\ }\hlstd{}\hlstd{\ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{bItM\ }\hlopt{=\ }\hlstd{bMatrix}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{40\ }\hlstd{}\hlstd{\ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{aItM\ }\hlopt{=\ }\hlstd{}\hlkwa{this}\hlstd{}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{41\ }\hlstd{}\hlstd{\ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{mNew\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$();}\\ \hllin{42\ }\hlstd{}\hlstd{\ \ \ }\hlstd{}\hlkwa{while}\hlstd{}\hlopt{(}\hlstd{bItM}\hlopt{.}\hlstd{}\hlkwd{hasNext}\hlstd{}\hlopt{())\{}\\ \hllin{43\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{bh\ }\hlopt{=\ }\hlstd{bItM}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{();}\\ \hllin{44\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{ah\ }\hlopt{=\ }\hlstd{aItM}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{();}\\ \hllin{45\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{bItN\ }\hlopt{=\ }\hlstd{bh}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{46\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{aItN\ }\hlopt{=\ }\hlstd{ah}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{47\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{h\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$();}\\ \hllin{48\ }\hlstd{}\hlstd{\ \ \ \ \ }\hlstd{}\hlkwa{while}\hlstd{}\hlopt{(}\hlstd{bItN}\hlopt{.}\hlstd{}\hlkwd{hasNext}\hlstd{}\hlopt{())\{}\\ \hllin{49\ }\hlstd{}\hlstd{\ \ \ \ \ \ }\hlstd{h}\hlopt{.}\hlstd{}\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{aItN}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{()+}\hlstd{bItN}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{());}\\ \hllin{50\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{}\hlopt{\}}\\ \hllin{51\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{mNew}\hlopt{.}\hlstd{}\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{h}\hlopt{);}\\ \hllin{52\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlopt{\}}\\ \hllin{53\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ new\ }\hlstd{}\hlkwd{Matrix}\hlstd{}\hlopt{(}\hlstd{mNew}\hlopt{);}\\ \hllin{54\ }\hlstd{\ }\hlopt{\}}\\ \hllin{55\ }\hlstd{\ Matrix\ }\hlkwd{sub}\hlstd{}\hlopt{(}\hlstd{Matrix\ bMatrix}\hlopt{)\ \{\ }\hlstd{}\hlslc{//矩阵减法}\\ \hllin{56\ }\hlstd{}\hlstd{\ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{bItM\ }\hlopt{=\ }\hlstd{bMatrix}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{57\ }\hlstd{}\hlstd{\ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{aItM\ }\hlopt{=\ }\hlstd{}\hlkwa{this}\hlstd{}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{58\ }\hlstd{}\hlstd{\ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{mNew\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$();}\\ \hllin{59\ }\hlstd{}\hlstd{\ \ \ }\hlstd{}\hlkwa{while}\hlstd{}\hlopt{(}\hlstd{bItM}\hlopt{.}\hlstd{}\hlkwd{hasNext}\hlstd{}\hlopt{())\{}\\ \hllin{60\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{bh\ }\hlopt{=\ }\hlstd{bItM}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{();}\\ \hllin{61\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{ah\ }\hlopt{=\ }\hlstd{aItM}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{();}\\ \hllin{62\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{bItN\ }\hlopt{=\ }\hlstd{bh}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{63\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{aItN\ }\hlopt{=\ }\hlstd{ah}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{64\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{h\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$();}\\ \hllin{65\ }\hlstd{}\hlstd{\ \ \ \ \ }\hlstd{}\hlkwa{while}\hlstd{}\hlopt{(}\hlstd{bItN}\hlopt{.}\hlstd{}\hlkwd{hasNext}\hlstd{}\hlopt{())\{}\\ \hllin{66\ }\hlstd{}\hlstd{\ \ \ \ \ \ }\hlstd{h}\hlopt{.}\hlstd{}\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{aItN}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{(){-}}\hlstd{bItN}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{());}\\ \hllin{67\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{}\hlopt{\}}\\ \hllin{68\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{mNew}\hlopt{.}\hlstd{}\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{h}\hlopt{);}\\ \hllin{69\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlopt{\}}\\ \hllin{70\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ new\ }\hlstd{}\hlkwd{Matrix}\hlstd{}\hlopt{(}\hlstd{mNew}\hlopt{);}\\ \hllin{71\ }\hlstd{\ }\hlopt{\}}\\ \hllin{72\ }\hlstd{\ Matrix\ }\hlkwd{mul}\hlstd{}\hlopt{(}\hlstd{Matrix\ bMatrix}\hlopt{)\ \{\ }\hlstd{}\hlslc{//\ 对应元素相乘}\\ \hllin{73\ }\hlstd{}\hlstd{\ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{bItM\ }\hlopt{=\ }\hlstd{bMatrix}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{74\ }\hlstd{}\hlstd{\ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{aItM\ }\hlopt{=\ }\hlstd{}\hlkwa{this}\hlstd{}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{75\ }\hlstd{}\hlstd{\ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$\ }\hlstd{mNew\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$$>$();}\\ \hllin{76\ }\hlstd{}\hlstd{\ \ \ }\hlstd{}\hlkwa{while}\hlstd{}\hlopt{(}\hlstd{bItM}\hlopt{.}\hlstd{}\hlkwd{hasNext}\hlstd{}\hlopt{())\{}\\ \hllin{77\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{bh\ }\hlopt{=\ }\hlstd{bItM}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{();}\\ \hllin{78\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{ah\ }\hlopt{=\ }\hlstd{aItM}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{();}\\ \hllin{79\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{bItN\ }\hlopt{=\ }\hlstd{bh}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{80\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{Iterator}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{aItN\ }\hlopt{=\ }\hlstd{ah}\hlopt{.}\hlstd{}\hlkwd{iterator}\hlstd{}\hlopt{();}\\ \hllin{81\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$\ }\hlstd{h\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{ArrayList}\hlopt{$<$}\hlstd{Integer}\hlopt{$>$();}\\ \hllin{82\ }\hlstd{}\hlstd{\ \ \ \ \ }\hlstd{}\hlkwa{while}\hlstd{}\hlopt{(}\hlstd{bItN}\hlopt{.}\hlstd{}\hlkwd{hasNext}\hlstd{}\hlopt{())\{}\\ \hllin{83\ }\hlstd{}\hlstd{\ \ \ \ \ \ }\hlstd{h}\hlopt{.}\hlstd{}\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{aItN}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{(){*}}\hlstd{bItN}\hlopt{.}\hlstd{}\hlkwd{next}\hlstd{}\hlopt{());}\\ \hllin{84\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{}\hlopt{\}}\\ \hllin{85\ }\hlstd{}\hlstd{\ \ \ \ }\hlstd{mNew}\hlopt{.}\hlstd{}\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{h}\hlopt{);}\\ \hllin{86\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlopt{\}}\\ \hllin{87\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ new\ }\hlstd{}\hlkwd{Matrix}\hlstd{}\hlopt{(}\hlstd{mNew}\hlopt{);}\\ \hllin{88\ }\hlstd{\ }\hlopt{\}}\\ \hllin{89\ }\hlstd{\ }\hlkwa{public\ }\hlstd{}\hlkwb{int\ }\hlstd{}\hlkwd{get\ }\hlstd{}\hlopt{(}\hlstd{}\hlkwb{int\ }\hlstd{a}\hlopt{,}\hlstd{}\hlkwb{int\ }\hlstd{b}\hlopt{)\{}\\ \hllin{90\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ }\hlstd{m}\hlopt{.}\hlstd{}\hlkwd{get}\hlstd{}\hlopt{(}\hlstd{a}\hlopt{{-}}\hlstd{}\hlnum{1}\hlstd{}\hlopt{).}\hlstd{}\hlkwd{get}\hlstd{}\hlopt{(}\hlstd{b}\hlopt{{-}}\hlstd{}\hlnum{1}\hlstd{}\hlopt{);}\\ \hllin{91\ }\hlstd{\ }\hlopt{\}}\\ \hllin{92\ }\hlstd{\ }\hlkwa{public\ static\ }\hlstd{}\hlkwb{void\ }\hlstd{}\hlkwd{main}\hlstd{}\hlopt{(}\hlstd{String}\hlopt{{[}{]}\ }\hlstd{args}\hlopt{)\ \{}\\ \hllin{93\ }\hlstd{\ \\ \hllin{94\ }\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"请输入矩阵的行数和列数,用空格分开"}\hlstd{}\hlopt{);}\\ \hllin{95\ }\hlstd{\ Scanner\ sc\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{}\hlkwd{Scanner}\hlstd{}\hlopt{(}\hlstd{System}\hlopt{.}\hlstd{}\hlkwa{in}\hlstd{}\hlopt{);}\\ \hllin{96\ }\hlstd{\ }\hlkwb{int\ }\hlstd{a\ }\hlopt{=\ }\hlstd{sc}\hlopt{.}\hlstd{}\hlkwd{nextInt}\hlstd{}\hlopt{();}\\ \hllin{97\ }\hlstd{\ }\hlkwb{int\ }\hlstd{b\ }\hlopt{=\ }\hlstd{sc}\hlopt{.}\hlstd{}\hlkwd{nextInt}\hlstd{}\hlopt{();}\\ \hllin{98\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"请依次输入矩阵1的每一行,每个元素用空格分开,回车输入下一行"}\hlstd{}\hlopt{);}\\ \hllin{99\ }\hlstd{\ Matrix\ matrix1\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{}\hlkwd{Matrix}\hlstd{}\hlopt{(}\hlstd{a}\hlopt{,}\hlstd{b}\hlopt{);}\\ \hllin{100\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"请依次输入矩阵2的每一行,每个元素用空格分开,回车输入下一行"}\hlstd{}\hlopt{);}\\ \hllin{101\ }\hlstd{\ Matrix\ matrix2\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{}\hlkwd{Matrix}\hlstd{}\hlopt{(}\hlstd{a}\hlopt{,}\hlstd{b}\hlopt{);}\\ \hllin{102\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"矩阵1和矩阵2相加结果:"}\hlstd{}\hlopt{);}\\ \hllin{103\ }\hlstd{\ Matrix\ matrixAdd\ }\hlopt{=\ }\hlstd{matrix1}\hlopt{.}\hlstd{}\hlkwd{add}\hlstd{}\hlopt{(}\hlstd{matrix2}\hlopt{);}\\ \hllin{104\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{matrixAdd}\hlopt{);}\\ \hllin{105\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"矩阵1和矩阵2相减结果:"}\hlstd{}\hlopt{);}\\ \hllin{106\ }\hlstd{\ Matrix\ matrixSub\ }\hlopt{=\ }\hlstd{matrix1}\hlopt{.}\hlstd{}\hlkwd{sub}\hlstd{}\hlopt{(}\hlstd{matrix2}\hlopt{);}\\ \hllin{107\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{matrixSub}\hlopt{);}\\ \hllin{108\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"矩阵1和矩阵2相乘结果:"}\hlstd{}\hlopt{);}\\ \hllin{109\ }\hlstd{\ Matrix\ matrixMul\ }\hlopt{=\ }\hlstd{matrix1}\hlopt{.}\hlstd{}\hlkwd{mul}\hlstd{}\hlopt{(}\hlstd{matrix2}\hlopt{);}\\ \hllin{110\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{matrixMul}\hlopt{);}\\ \hllin{111\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"请输入在矩阵1中要获得的元素角标,用空格分开"}\hlstd{}\hlopt{);}\\ \hllin{112\ }\hlstd{\ sc\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{}\hlkwd{Scanner}\hlstd{}\hlopt{(}\hlstd{System}\hlopt{.}\hlstd{}\hlkwa{in}\hlstd{}\hlopt{);}\\ \hllin{113\ }\hlstd{\ a\ }\hlopt{=\ }\hlstd{sc}\hlopt{.}\hlstd{}\hlkwd{nextInt}\hlstd{}\hlopt{();}\\ \hllin{114\ }\hlstd{\ b\ }\hlopt{=\ }\hlstd{sc}\hlopt{.}\hlstd{}\hlkwd{nextInt}\hlstd{}\hlopt{();}\\ \hllin{115\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"该元素是:"}\hlstd{}\hlopt{+}\hlstd{matrix1}\hlopt{.}\hlstd{}\hlkwd{get}\hlstd{}\hlopt{(}\hlstd{a}\hlopt{,}\hlstd{b}\hlopt{));}\\ \hllin{116\ }\hlstd{\ System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{}\hlstr{"Fibonacci数列前20项:"}\hlstd{}\hlopt{);}\\ \hllin{117\ }\hlstd{\ Fibonacci}\hlopt{.}\hlstd{}\hlkwd{main}\hlstd{}\hlopt{(}\hlstd{args}\hlopt{);}\\ \hllin{118\ }\hlstd{\ }\hlopt{\}}\\ \hllin{119\ }\hlstd{}\hlopt{\}}\\ \hllin{120\ }\hlstd{}\hlkwa{class\ }\hlstd{Fibonacci\ }\hlopt{\{}\\ \hllin{121\ }\hlstd{\ }\hlkwb{int}\hlstd{}\hlopt{{[}{]}\ }\hlstd{f}\hlopt{;}\\ \hllin{122\ }\hlstd{\ }\hlkwd{Fibonacci}\hlstd{}\hlopt{(}\hlstd{}\hlkwb{int\ }\hlstd{num}\hlopt{)\ \{}\\ \hllin{123\ }\hlstd{}\hlstd{\ \ }\hlstd{f\ }\hlopt{=}\hlstd{}\hlkwa{new\ }\hlstd{}\hlkwb{int}\hlstd{}\hlopt{{[}}\hlstd{num}\hlopt{{]};}\\ \hllin{124\ }\hlstd{}\hlstd{\ \ }\hlstd{f}\hlopt{{[}}\hlstd{}\hlnum{0}\hlstd{}\hlopt{{]}\ =\ }\hlstd{}\hlnum{1}\hlstd{}\hlopt{;}\\ \hllin{125\ }\hlstd{}\hlstd{\ \ }\hlstd{f}\hlopt{{[}}\hlstd{}\hlnum{1}\hlstd{}\hlopt{{]}\ =\ }\hlstd{}\hlnum{1}\hlstd{}\hlopt{;}\\ \hllin{126\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{for}\hlstd{}\hlopt{(}\hlstd{}\hlkwb{int\ }\hlstd{i\ }\hlopt{=}\hlstd{}\hlnum{2}\hlstd{}\hlopt{;}\hlstd{i}\hlopt{$<$}\hlstd{num}\hlopt{;}\hlstd{i}\hlopt{++)\ \{}\\ \hllin{127\ }\hlstd{}\hlstd{\ \ \ }\hlstd{f}\hlopt{{[}}\hlstd{i}\hlopt{{]}\ =\ }\hlstd{f}\hlopt{{[}}\hlstd{i}\hlopt{{-}}\hlstd{}\hlnum{1}\hlstd{}\hlopt{{]}+}\hlstd{f}\hlopt{{[}}\hlstd{i}\hlopt{{-}}\hlstd{}\hlnum{2}\hlstd{}\hlopt{{]};}\\ \hllin{128\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlopt{\}}\\ \hllin{129\ }\hlstd{\ }\hlopt{\}}\\ \hllin{130\ }\hlstd{\ }\hlkwa{public\ }\hlstd{String\ }\hlkwd{toString}\hlstd{}\hlopt{()\ \{}\\ \hllin{131\ }\hlstd{}\hlstd{\ \ }\hlstd{String\ s\ }\hlopt{=\ }\hlstd{}\hlstr{""}\hlstd{}\hlopt{;}\\ \hllin{132\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{for}\hlstd{}\hlopt{(}\hlstd{}\hlkwb{int\ }\hlstd{i\ }\hlopt{:\ }\hlstd{f}\hlopt{)}\\ \hllin{133\ }\hlstd{}\hlstd{\ \ }\hlstd{s\ }\hlopt{+=\ }\hlstd{i}\hlopt{+}\hlstd{}\hlstr{","}\hlstd{}\hlopt{;}\\ \hllin{134\ }\hlstd{}\hlstd{\ \ }\hlstd{}\hlkwa{return\ }\hlstd{s}\hlopt{;}\\ \hllin{135\ }\hlstd{\ }\hlopt{\}}\\ \hllin{136\ }\hlstd{\ }\hlkwa{public\ static\ }\hlstd{}\hlkwb{void\ }\hlstd{}\hlkwd{main}\hlstd{}\hlopt{(}\hlstd{String}\hlopt{{[}{]}\ }\hlstd{args}\hlopt{)\ \{}\\ \hllin{137\ }\hlstd{}\hlstd{\ \ }\hlstd{Fibonacci\ ff\ }\hlopt{=\ }\hlstd{}\hlkwa{new\ }\hlstd{}\hlkwd{Fibonacci}\hlstd{}\hlopt{(}\hlstd{}\hlnum{20}\hlstd{}\hlopt{);}\\ \hllin{138\ }\hlstd{}\hlstd{\ \ }\hlstd{System}\hlopt{.}\hlstd{out}\hlopt{.}\hlstd{}\hlkwd{println}\hlstd{}\hlopt{(}\hlstd{ff}\hlopt{);}\\ \hllin{139\ }\hlstd{\ }\hlopt{\}}\\ \hllin{140\ }\hlstd{}\hlopt{\}}\\ \hllin{141\ }\hlstd{\\ \hllin{142\ }}\hlstd{\ \ }\hlstd{} \mbox{} \normalfont \normalsize