Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- =====================================================
- chapter 5: Arrays
- Ex11: Display matrix and max value placed in frame
- =====================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- final int SIZE=10;
- int matrix[][]=new int[SIZE][SIZE];
- int row=0,col=0;
- int max;
- Scanner s=new Scanner(System.in);
- boolean loop=true;
- System.out.println("Enter rows: ");
- row=s.nextInt();
- while(row<=0 || row>SIZE){
- System.out.println("try again: ");
- row=s.nextInt();
- }
- System.out.println("Enter cols: ");
- col=s.nextInt();
- while(col<=0 || col>SIZE){
- System.out.println("try again: ");
- col=s.nextInt();
- }
- System.out.println("Enter "+row*col+" values: ");
- max=matrix[0][0];
- for(int i=0;i<row;i++){
- for(int j=0;j<col;j++){
- matrix[i][j]=s.nextInt();
- System.out.print(matrix[i][j]+"\t\t");
- if( (i==0 || i==row-1 ) && matrix[i][j]>max)
- max=matrix[i][j];
- if( (i!=0 && i!=row-1 && j==0 ) && matrix[i][j]>max )
- max=matrix[i][j];
- if( (i!=0 && i!=row-1 && j==col-1 ) && matrix[i][j]>max )
- max=matrix[i][j];
- }
- System.out.println();
- }
- System.out.println("max frame value: "+max);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment