Menu
Question Index
...


Write a program to print the characters at the given location in a matrix. If the point is 5-1-T, we need to print T at the row 5 and the column 1. If it is 4-3-M, we need to print M at row 4 and column 3. Rows and columns are counted starting from 1.

Input (List) Output (String)
[1-1-M, 2-1-E, 3-1-R, 4-1-I, 5-1-T, 1-5-C, 2-5-A, 3-5-M, 4-5-P, 5-5-U, 6-5-S] M---C
E---A
R---M
I---P
T---U
----S
[1-1-M, 1-2-E, 1-3-R, 1-4-I, 1-5-T, 4-1-C, 4-2-A, 4-3-M, 4-4-P, 4-5-U, 4-6-S] MERIT-
------
------
CAMPUS
[1-1-A, 1-2-Z, 1-3-B, 1-4-Y, 1-5-C, 1-6-X, 2-1-W, 2-2-D, 2-3-V, 2-4-E, 2-5-U, 2-6-F, 3-1-G, 3-2-T, 3-3-H, 3-4-S, 3-5-I, 3-6-R] AZBYCX
WDVEUF
GTHSIR
[1-2-M, 5-18-I, 5-9-V, 1-6-B, 1-10-E, 1-12-N, 5-3-K, 3-8-I, 5-6-A, 3-5-A, 5-12-A, 1-8-E, 5-15-L, 1-4-O, 3-1-S, 3-3-H, 3-11-K] -M-O-B-E-E-N------
------------------
S-H-A--I--K-------
------------------
--K--A--V--A--L--I
[5-9-S, 11-7-A, 1-7-K, 10-3-B, 11-11-T, 8-10-C, 6-6-M, 4-3-N, 2-2-P, 1-5-U] ----U-K----
-P---------
-----------
--N--------
--------S--
-----M-----
-----------
---------C-
-----------
--B--------
------A---T

class PrintCharactersInMatrix

{    public static void main(String s[])
    {
        ArrayList points = new ArrayList();
        points.add(new Point(1, 1, 'M'));
        points.add(new Point(2, 1, 'E'));
        points.add(new Point(3, 1, 'R'));
        points.add(new Point(4, 1, 'I'));
        points.add(new Point(5, 1, 'T'));
        points.add(new Point(1, 5, 'C'));
        points.add(new Point(2, 5, 'A'));
        points.add(new Point(3, 5, 'M'));
        points.add(new Point(4, 5, 'P'));
        points.add(new Point(5, 5, 'U'));
        points.add(new Point(6, 5, 'S'));
        printCharacterMatrix(points);

    }


public static void printCharacterMatrix(ArrayList<Point> points) {
//Write code here to print the characters in the matrix
}
}
class Point {

int x;
int y;
char c;

Point(int x, int y, char c) {
this.x = x;
this.y = y;
this.c = c;
}

@Override
public String toString() {
return x + "-" + y + "-" + c;
}
}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App