week13.pdf - CSC 111 Week 13 Tutorial#9 Method II Q1 Write a method called printBoundary that print the boundary(border elements of 2-­‐D array Note

week13.pdf - CSC 111 Week 13 Tutorial#9 Method II Q1 Write...

This preview shows page 1 - 6 out of 10 pages.

Method II CSC 111 Week 13 Tutorial #9
Image of page 1

Subscribe to view the full document.

Q1: Write a method called printBoundary that print the boundary (border) elements of 2-­‐D array. Note: You should prompt the user to enter the size and the elements of the array in a separate method called fillArray.
Image of page 2
Answer //import necessary packages import java.util.*; class Boundary { static Scanner input = new Scanner (System.in); public static void main(String args[]) { int row,col; System.out.print( "Enter the no. of rows: " ); //Inputting the number of rows row=input.nextInt(); System.out.print( "Enter the no. of columns: " ); //Inputting the number of columns col=input.nextInt(); int [][] matrix = new int [row][col]; //Creating the array fillArray(matrix); printBoundary(matrix); } //end main
Image of page 3

Subscribe to view the full document.

fillArray( int [][] matrix) public static void fillArray( int [][] matrix) { /* Inputting the array */ System.out.print( "Enter the elements of the 2-D array: " ); for ( int i=0;i<matrix.length;i++) for ( int j=0;j<matrix[0].length;j++) { matrix[i][j]=input.nextInt(); } } //end fillArray
Image of page 4
printBoundary( int [][] matrix) public static void printBoundary( int [][] matrix) { System.out.println(
Image of page 5

Subscribe to view the full document.

Image of page 6
  • Fall '10
  • ZuhairShentuf
  • Array, Row, public static void, int row, static Scanner input

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes