8.13 Smallest element
- import java.util.Scanner;
- public class SmallestArrayElement {
- public static void main(String[] args) {
- int iRow,iCol;
- int i,j;
- double dSmall;
- int iTempR,iTempC;
- Scanner input = new Scanner(System.in);
- iRow = input.nextInt();
- iCol =input.nextInt();
- double [][]SmallestA = new double[iRow][iCol];
- dSmall = 10000;
- iTempR = iTempC = 0;
- for ( i=0 ; i<iRow ; i++ )
- for ( j=0 ; j<iCol ; j++ )
- {
- SmallestA[i][j] = input.nextDouble();
- if ( SmallestA[i][j] < dSmall )
- {
- dSmall = SmallestA[i][j];
- iTempR = i;
- iTempC = j;
- }
- }
- System.out.println("location of the smallest array (" + iTempR + " " + iTempC + ")");
- }
- }
Find the location of the smallest element in the two dimension array
留言
張貼留言