. Remove all the blank spaces between
character.Matrix is of 10* 10.
eg: INPUT
------------------------------------
| N | A | | V | |T
-------------------------------------
| |G | U | |P |
--------------------------------------
|T | | | A | |
------------------------------------
OUTPUT:
------------------------------------
| N | A | V | T | |
-------------------------------------
|G |U | P | | |
--------------------------------------
|T | A | | | |
------------------------------------

Answer Posted / kiran

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package removespacesfrommatrix;

/**
*
* @author Sunshine
*/
public class RemoveSpacesFromMatrix {

void print(char[][] matrix) {
char temp;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (matrix[i][j] != ' ') {
System.out.println(matrix[i][j]);
} else {
temp = matrix[i][j + 1];
matrix[i][j] = temp;
matrix[i][j + 1] = ' ';
System.out.println(matrix[i][j]);
}
}
}
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
char[][] matrix;
matrix = new char[][]{{'a', 'b', ' ', 'c'}, {' ', 'd', ' ', 'f'}, {' ', ' ', 'x', 'y'}, {'m', 'n', 'o', 'p'}};
RemoveSpacesFromMatrix r = new RemoveSpacesFromMatrix();
r.print(matrix);
}
}

Is This Answer Correct ?    0 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What output does the following code generate? Why? What output does it generate if you make A::Foo() a pure virtual function? class A { A() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; class B : public A { B() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; int main(int, char**) { A objectA; B objectB; return 0; }

644


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

3274


How can I Draw an ellipse in 3d space and color it by using graph3d?

2138


develop a program to calculate and print body mass index for 200 employees

2216


solve the problem in the programming language C++"if a five digit number is input through the keyboard.Write a program to calculate the sum of its digits(hint: use the modulus operator)

2937






i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.

1972


What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }

580


U hv to enter a range from a and b and search hw many no. of times a pattern n. occurs between the range a and b. Eg :i/p:enter range :0 100 Enter pattern: 13 o/p: the no. times 13 occurred betwwn 0 to 100:1 Eg :i/p:enter range :100 1000 Enter pattern: 13 o/p: the no. times 13 occurred betwwn 100 to 1000: (in this 13,113,131,132,133…139,213,313,…913 all these will be counted)

2127


write a program using 2 D that searches a number and display the number of items 12 inputs values input 15,20, 13, 30, 38, 40,16, 18, 20 ,18 ,20 enter no. to search : 20

3368


write a program to convert temperature from fa height into celcius and vise versa,use modular programming

2441


Definition of priority queue was given. We have to implement the priority queue using array of pointers with the priorities given in the range 1..n. The array could be accessed using the variable top. The list corresponding to the array elements contains the items having the priority as the array index. Adding an item would require changing the value of top if it has higher priority than top. Extracting an item would require deleting the first element from the corresponding queue. The following class was given: class PriorityQueue { int *Data[100]; int top; public: void put(int item, int priority); // inserts the item with the given priority. int get(int priority); // extract the element with the given priority. int count(); // returns the total elements in the priority queue. int isEmpty(); // check whether the priority queue is empty or not. }; We had to implement all these class functions.

4398


output for printf("printf");

1985


find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L

2010


Code for Method of Handling Factorials of Any Size?

2008


write a program that reads a series of strings and prints only those strings begging with letter "b"

2674