8.13 Smallest element

  1. import java.util.Scanner;
  2. public class SmallestArrayElement {
  3.  
  4.     public static void main(String[] args) {
  5.         int iRow,iCol;
  6.         int i,j;
  7.         double dSmall;
  8.         int iTempR,iTempC;
  9.         Scanner input = new Scanner(System.in);
  10.         iRow = input.nextInt();
  11.         iCol =input.nextInt();
  12.         double [][]SmallestA = new double[iRow][iCol];
  13.         dSmall = 10000;
  14.         iTempR = iTempC = 0;
  15.         for ( i=0 ; i<iRow ; i++ )
  16.             for ( j=0 ; j<iCol ; j++ )
  17.             {
  18.             SmallestA[i][j] = input.nextDouble();      
  19.             if ( SmallestA[i][j] < dSmall )
  20.                 {
  21.                 dSmall = SmallestA[i][j];
  22.                 iTempR = i;
  23.                 iTempC = j;
  24.                 }
  25.             }
  26.         System.out.println("location of the smallest array (" + iTempR + " " + iTempC + ")");
  27.     }
  28. }
Find the location of the smallest element in the two dimension array

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year