Hi, I'm doing a matrix of array n I have to assign each column with a letter or number so that when I shuffle the letters/numbers, it will print out accordingly. this is like the transposition cipher. I have 2 problems.
1. my matrix is not printing out like i want it to which is 5x6. instead it's printing out line by line. I've checked my code with everyone n it's the same. help me figure out what im missing.
2.how do you assign a letter or number to a column?? i've tried using strings and assign the column, but it doesn't work if i need to code the column using numbers. this is what i tried: String 1 = array[][1];
here is my code:
public class Secret {
public static void main(String[]args) {
String str = "this is my very secret message";
int len = str.length();
char array [][] = new char[5][6];
int x = 0;
for (int i = 0; i<5; i++){
for (int j = 0; j<6; j++){
while (x<len) {
char ch = str.charAt(x);
x++;
array[i][j] = ch;
System.out.println(array[i][j] +" ");
}
}
}
}
}
the outcome tht i'm looking for is:
4 5 3 2 9 7
t h i s i
s m y v
e r y s e
c r e t m
e s s a g e
(ok, the matrix is not typing out as i would have liked but it's taking into consideration the space as well.)
when i type 794532 it will come out according to the column.
if you could help me tht would be great. thank you kindly.