日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java黑皮书课后题第9章:**9.13(Location类)设计一个名为Location的类,定位二维数组中的最大值及其位置。

發布時間:2024/8/1 java 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java黑皮书课后题第9章:**9.13(Location类)设计一个名为Location的类,定位二维数组中的最大值及其位置。 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Java黑皮書課后題第9章:**9.13(Location類)設計一個名為Location的類,定位二維數組中的最大值及其位置

  • 題目
    • 破題
  • 代碼
    • Test13
    • Test13_Location
    • 運行結果

題目

破題

Test13:測試程序
Test13_Location:實現題目要求

代碼

Test13

import java.util.Scanner;public class Test13 {public static void main(String[] args) {// 定義數組Scanner input = new Scanner(System.in);System.out.print("Enter the number of rows and columns in the array:");int rows = input.nextInt(), cols = input.nextInt();double[][] arr = new double[rows][cols];// 數組賦值System.out.println("Enter the array:");for (int a = 0 ; a < rows ; a++){for (int b = 0 ; b < cols ; b++){arr[a][b] = input.nextDouble();}}// 調用找最大值方法Test13_Location l = new Test13_Location();l = locateLargest(arr);// 輸出結果System.out.println("The location of the largest elements is " + Test13_Location.maxValue +" at (" + Test13_Location.row + ", " + Test13_Location.column + ")");}public static Test13_Location locateLargest(double[][] a){Test13_Location l = new Test13_Location();for (int m = 0 ; m < a.length ; m++){for (int n = 0 ; n < a[0].length ; n++){if (Test13_Location.maxValue < a[m][n]){Test13_Location.maxValue = a[m][n];Test13_Location.row = m;Test13_Location.column = n;}}}return l;} }

Test13_Location

public class Test13_Location {public static int row = 0, column = 0;public static double maxValue = 0.0; }

運行結果

Enter the number of rows and columns in the array:3 4 Enter the array: 23.5 35 2 10 4.5 3 45 3.5 35 44 5.5 9.6 The location of the largest elements is 45.0 at (1, 2)

總結

以上是生活随笔為你收集整理的Java黑皮书课后题第9章:**9.13(Location类)设计一个名为Location的类,定位二维数组中的最大值及其位置。的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。