-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.java
1540 lines (877 loc) · 29.4 KB
/
main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package r;
import java.util.*;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
class Word_Guess {
int score;
static int wordIndex=0;
Word_Guess(){
score=0;
rules1();
}
public void word_guess() {
Scanner scanner = new Scanner(System.in);
// Words to be guessed
String[] words= {"Quicksort","array" ,"object","abstraction","encapsulation","stack","queue","inheritance"};
//Hints
String[] hint= {"Most Efficient Sorting Algorithm","Data structure for storing elements of same data type only","Instance of class","Hiding implementation details","Uses public getter and setter method to access private data","Used for DFS traversal","Used for BFS traversal","Designing new class from already existing class"};
Random random =new Random();
//RandomIndex will be assigned
int randomIndex=random.nextInt(words.length);
int e;
// Creating stack to store guess letters
Stack<Character> guessed = new Stack<>();
// Maximum incorrect gueeses here are 4 which means player have 4 chances which may be incorrect letter.
int maxIncorrectGuesses = 4;
//Traversing till last word in words array
while (randomIndex < words.length) {
//wordToGuess is a variable which is used to access words present in words array
int i;
do {
System.out.println("Let's find the word!!\n");
String wordToGuess = words[randomIndex].toLowerCase();
String h2=hint[randomIndex];
//To store length of word
int wordLength = wordToGuess.length();
int incorrectGuesses = 0;
System.out.println("Word " + (wordIndex+1) + ":");
while (incorrectGuesses < maxIncorrectGuesses) {
// Display the current state of the word
System.out.println("Hint:"+h2);
System.out.println();
for (i = 0; i < wordLength; i++) {
char letter = wordToGuess.charAt(i);
//Checking if stack guess contain any letter
if (guessed.contains(letter)) {
System.out.print(letter + " ");
//If not then print dash
} else {
System.out.print(" _ ");
}
}
System.out.println();
// Display guessed letters
String input;
System.out.print("Guessed letters:" + guessed+"\n");
// Ask user to enter letter
System.out.print("\nGuess a letter: \n");
input = scanner.nextLine();
// Check if the input is a single letter
if (input.length() != 1 || !Character.isLetter(input.charAt(0))) {
System.out.println("Please enter a single letter.");
continue;
}
char guess = input.toLowerCase().charAt(0);
// Check if the letter has already been guessed i.e.already present in stack
if (guessed.contains(guess)) {
//If user enters letter which is already guessed
System.out.println("You've already guessed that letter.\n");
continue;
}
// Add the letter to the guessed stack
guessed.push(guess);
// Check if the letter is in the word to guess
if (!wordToGuess.contains(String.valueOf(guess))) {
incorrectGuesses++;
System.out.println("Incorrect guess. Last " + (maxIncorrectGuesses - incorrectGuesses) + " chance left.");
}
// Check if the word has been completely guessed
boolean wordGuessed = true;//If stack doesn't contain any character from given word or checks if a character is a space then mark it as false
for ( i = 0; i < wordLength; i++) {
if (!guessed.contains(wordToGuess.charAt(i)) && wordToGuess.charAt(i) != ' ') {
wordGuessed = false;
break;
}
}
if (wordGuessed) {
System.out.println("Congratulations! You've guessed the word: " + wordToGuess+"\n");
score=score+10;
break;
}
}
// If the player runs out of guesses, reveal the word
if (incorrectGuesses == maxIncorrectGuesses) {
System.out.println("You've exceeded guessing limit. The word was: " + wordToGuess+"\n");
}
// Clear guessed letters for the next word i.e.Make stack empty
guessed.clear();
//Incrementing for traversing to next word
randomIndex++;
wordIndex++;
System.out.println("Points earned:"+" "+score+" "+"\n");
System.out.println("Do you want to quit? Enter 1 for yes and 0 for No.");
e=scanner.nextInt();
}while(e!=0);
if(e==0) {
return;
}
}
}
//Displaying rules of games
void rules1() {
System.out.println("-------------------------Let's Guess the Word!!-----------------\n");
System.out.println("-------------------------ABOUT THE GAME--------------------------\n");
System.out.println("As name suggests it is a word guessing game.the player's objective is to guess a hidden word from a predefined list of words.\n The game uses a console-based interface and provides the player with a limited number of chances to guess the correct word \n\n");
System.out.println("RULES AND INSTRUCTIONS:");
System.out.println("--------------------------------------------------------------------------------------------------------");
System.out.println("1.Player's task is to guess correct letters from word and then it will be automatically displayed if the guess is right or wrong.");
System.out.println("2.Entered character should be strictly an alphabet");
System.out.println("3.For guessing each word only 6 chances will be given");
System.out.println("4.If user miss to guess word within 6 chances then you will be directed to next word and correct answer will be displayed");
System.out.println("--------------------------------------------------------------------------------------------------------");
}
}
class Node {
String word;
String keyword;
String key;
String encryptword;
Node left;
Node right;
public Node(String word, String keyword, String key, String encryptword) {
this.word = word;
this.keyword = keyword;
this.key = key;
this.encryptword = encryptword;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
private Node root;
int count;
Scanner sc=new Scanner (System.in);
public BinarySearchTree() {
root = null;
count=0;
}
public void insert(String word, String keyword, String key, String encryptword) {
root = insertRec(root, word, keyword, key, encryptword);
}
private Node insertRec(Node root, String word, String keyword, String key, String encryptword) {
if (root == null) {
return new Node(word, keyword, key, encryptword);
}
if (word.compareTo(root.word) < 0) {
root.left = insertRec(root.left, word, keyword, key, encryptword);
} else if (word.compareTo(root.word) > 0) {
root.right = insertRec(root.right, word, keyword, key, encryptword);
}
return root;
}
public static void printVigenereSquare() {
System.out.println("Vigenère Square:");
// Determine the width of each cell to center-align
int cellWidth = 3;
for (char c = 'A'; c <= 'Z'; c++) {
for (char d = 'A'; d <= 'Z'; d++) {
String cell = String.format("%" + cellWidth + "s", (char)('A' + (c - 'A' + d - 'A') % 26));
System.out.print(cell);
}
System.out.println();
}
}
void cryption(Node ptr) {
int[] opt= {1,2};
Random random = new Random();
int randomIndex = random.nextInt(2);
int choice = opt[randomIndex];
switch (choice) {
case 1:
System.out.println("word:"+ptr.word);
System.out.println(" HINT:lOOK FOR WORD LETTERS IN ROW AND KEY LETTERS IN COLUMN");
System.out.println("Encrypt the message:");
printVigenereSquare();
String en=sc.nextLine();
if(ptr.encryptword.compareTo(en)==0) {
System.out.println("Congrats!! you got it correct");
count=count+10;
System.out.println("YOUR SCORE : "+count);
}
else {System.out.println("Gotcha!!Its wrong");
System.out.println("The Encrypted word is:"+ptr.encryptword);
}
break;
case 2:
System.out.println("word:"+ptr.encryptword);
System.out.println(" HINT:lOOK FOR WORD LETTERS IN COLUMN AND KEY LETTERS IN ROW");
System.out.println("Decrypt the message:");
printVigenereSquare();
String dn=sc.nextLine();
if(ptr.word.compareTo(dn)==0) {
System.out.println("Congrats!!!");
}
else {System.out.println("Gotcha!!Its wrong");
System.out.println("The word is:"+ptr.word);
}
}
}
void search1(String key) {
int flag=0;
Node ptr=root;
while(ptr!=null) {
if(ptr.word.compareTo(key)==0) {
System.out.println("keyword="+ptr.keyword);//hint
System.out.println("key="+ptr.key);
cryption(ptr);
flag=1;
break;
}
if(ptr.word.compareTo(key)>0)
ptr=ptr.left;
else
ptr=ptr.right;
}
if(flag==0) {
System.out.println("word not found");
}
}
}
class cipher
{ String dword,eword,keyword;
cipher(String d,String k){
dword=d;
keyword=k;
}
cipher(){
System.out.println("*************************************WELCOME**************************************");
System.out.println("--------------------------------------------------------------------------------------------------------");
System.out.println(" Cipher Quest: The Vigenère Challenge ");
System.out.println("--------------------------------------------------------------------------------------------------------");
System.out.println(" Prepare to embark on a thrilling journey into the world of secret codes");
System.out.println("Rules");
System.out.println("--------------------------------------------------------------------------------------------------------");
System.out.println("1.The game wants you to encrypt or decrypt the word.WRITE IN CAPITAL LETTERS!!!");
System.out.println("2.BE Aware!!Question will randomly generate an encrypted or decrypted word ");
System.out.println("3.A key will be provided and Vigenere table will be displayed for reference");
System.out.println();
System.out.println("4.To DECRYPT Follow this:\r\n"
+ "The first letter is selected using the priming key.\r\n"
+ "The first letter of the ciphertext is located in this row.\r\n"
+ "The first letter of the plaintext will be the letter where the first row and column intersect.\r\n"
+ "This process is followed until the entire ciphertext is deciphered.\r\n"
+ "");
System.out.println();
System.out.println("5.To ENCRYPT FOLLOW this:\r\n "
+ "The first letter of the ciphertext will be the letter where the first row and column intersect. \r\n"
+ "Now, this process is continued Write the plaintext.\r\n"
+ "Use the plaintext and the key letter to select a row and a column in the Vigenere table.\r\n"
+ "The first letter of the plaintext is the first row and the key is the first column. ");
}
public void encryptDecrypt(String plaintext, String keyword)
{
//Converting plaintext to char array
char msg[] = plaintext.toCharArray();
int msgLen = msg.length;
int i,j;
// Creating new char arrays
char key[] = new char[msgLen];
char encryptedMsg[] = new char[msgLen];
char decryptedMsg[] = new char[msgLen];
/* generate key, using keyword in cyclic
manner equal to the length of
original message i.e plaintext */
for(i = 0, j = 0; i < msgLen; ++i, ++j)
{
if(j == keyword.length())
{
j = 0;
}
key[i] = keyword.charAt(j);
}
//encryption code
for(i = 0; i < msgLen; ++i)
encryptedMsg[i] = (char) (((msg[i] + key[i]) % 26) + 'A');
//decryption code
for(i = 0; i < msgLen; ++i)
decryptedMsg[i] = (char)((((encryptedMsg[i] - key[i]) + 26) % 26) + 'A');
System.out.println("Original Message: " + plaintext);
System.out.println("Keyword: " + keyword);
/* String.valueOf() method converts
char[] to String */
System.out.println("Key: " + String.valueOf(key));
System.out.println();
System.out.println("Encrypted Message: " + String.valueOf(encryptedMsg));
System.out.println();
System.out.println("Decrypted Message: " + String.valueOf(decryptedMsg));
}
public void crypto() {
Scanner sc=new Scanner (System.in);
BinarySearchTree bst = new BinarySearchTree();
bst.insert("ORIGINAL", "FAKE", "FAKEFAKE", "TRSKNNKP");
bst.insert("HAPPINESS", "REQUIRED", "REQUIREDR", "YEFJQEIVJ");
bst.insert("GESTURE", "WARM", "WARMWAR", "CEJFQRV");
bst.insert("GUINNESS", "RECORD", "RECORDRE", "XYKBEHJW");
bst.insert("APPLE", "OPEN", "OPENO", "OETYS");
bst.insert("MAGIC", "JAADU", "JAADU", "VAGLW");
bst.insert("MESMERIZING", "DARK", "DARKDARKDAR", "PEJWHRZJLNX");
bst.insert("ILOVEJAVA", "LEMON", "LEMONLEMO", "TPAJRUEHO");
bst.insert("TRANQUIL", "CALM", "CALMCALM", "VRLZSUTX");
bst.insert("QUEEN", "KING", "KINGK", "ACRKX");
bst.insert("POPULAR", "FAME", "FAMEFAM", "UOBYQAD");
bst.insert("THANKSFORPLAYING", "ROSE", "ROSEROSEROSEROSE", "KVSRBGXSIDDEPWFK");
bst.insert("YOUAREBEAUTIFUL", "LOOK", "LOOKLOOKLOOKLOO", "JCIKCSPOLIHSQIZ");
bst.insert("WONDERFUL", "COLORFUL", "COLORFULC", "YCYRVWZFN");
bst.insert("YOUNGER", "ELDER", "ELDEREL", "CZXRXIC");
// Generate random words to search
String[] wordsToSearch = {"APPLE", "ILOVEJAVA", "YOUAREBEAUTIFUL", "HAPPINESS", "MESMERIZING", "WONDERFUL","QUEEN","TRANQUIL","POPULAR","YOUNGER","GESTURE","ORIGINAL","GUINNESS","MAGIC","THANKSFORPLAYING"};
Random random = new Random();
int ch=1;
while (ch!=0) {
int randomIndex = random.nextInt(wordsToSearch.length);
String searchWord = wordsToSearch[randomIndex];
bst.search1(searchWord);
System.out.println("wanna continue playing?If yes press 1 else press 0 :");
ch=sc.nextInt();
}
}
}
class ROranges{
int arr[][]= new int[6][6];
ROranges(){
rules();
}
void g() {
Random r= new Random();
for(int i=0;i<6;i++) {
for(int j=0;j<6;j++) {
int h=r.nextInt();
int d=h % 3;
if(d<0) {
d=-d;
}
arr[i][j]= d;
}
}
oran(6,6);
}
Scanner sc = new Scanner(System.in);
void oran(int x,int y) {
Orange n= new Orange(x,y);
for(int i=0;i<x;i++) {
for(int j=0;j<y;j++) {
System.out.print(" "+arr[i][j]);
}
System.out.println();
}
System.out.println();
int ans = n.rotOranges(arr);
while(true) {
System.out.println(" TO | TO PRESS : |");
System.out.println(" ------------|--------------------------------------|");
System.out.println(" SEE ANSWER | 'Y' (THERE BY YOU WILL END THE GAME) |");
System.out.println(" CONTINUE | 'N' OR ANY CHARACTER KEY |");
System.out.println(" QUIT | 'Q' |");
System.out.println(" ------------|--------------------------------------|");
System.out.println("");
System.out.println(" ENTER YOUR CHOICE :");
char d=sc.next().charAt(0);
if(d=='q' || d=='Q') {
return;
}
else if(d!='y' && d!='Y') {
System.out.println("\nEnter your answer : ");
int g=sc.nextInt();
int f=1;
if(g!=ans) {
System.out.println("Your answer is wrong !! \n\n ");
f++;
} else if(ans==g) {
System.out.println(" CONGRATULATIONS !!!! \n\n YOU WON !! ");
}
else {
}}
else {
System.out.println(" Correct anwer is :\n");
if (ans == -1)
System.out.println( "All oranges cannot rot");
else
System.out.println(
" Time required for all oranges to rot : "
+ ans);;
return ;
}}
}
class Orange{
int R =0,C=0;
List<O> b= new ArrayList<>();
public Orange(int n,int m) {
R=n;
C=m;
}
class Ele {
int x = 0;
int y = 0;
Ele(int x, int y)
{
this.x = x;
this.y = y;
}
}
void ans() {
for(int i=0;i<b.size();i++) {
System.out.println("LOCATION : "+b.get(i).i+" , "+b.get(i).j+" | TIME : "+b.get(i).t+"min");
}
}
boolean isValid(int i, int j)
{
return (i >= 0 && j >= 0 && i < R && j < C);
}
boolean isDelim(Ele temp)
{
return (temp.x == -1 && temp.y == -1);
}
// Function to check whether there is still a fresh
// orange remaining
boolean checkAll(int arr[][])
{
for (int i = 0; i < R; i++)
for (int j = 0; j < C; j++)
if (arr[i][j] == 1)
return true;
return false;
}
// This function finds if it is possible to rot all
// oranges or not. If possible, then it returns minimum
// time required to rot all, otherwise returns -1
class O{
int i, t,j;
O(int i,int j,int t){
this.i=i;
this.j=j;
this.t=t;
}
}
int rotOranges(int arr[][])
{
// Create a queue of cells
Queue<Ele> Q = new LinkedList<>();
Ele temp;
int ans = 0;
// Store all the cells having rotten orange in first
// time frame
for (int i = 0; i < R; i++)
for (int j = 0; j < C; j++)
if (arr[i][j] == 2)
Q.add(new Ele(i, j));
Q.add(new Ele(-1, -1));
while (!Q.isEmpty()) {
// This flag is used to determine whether even a
// single fresh orange gets rotten due to rotten
// oranges in the current time frame so we can
// increase the count of the required time.
boolean flag = false;
// Process all the rotten oranges in current
// time frame.
while (!isDelim(Q.peek())) {
temp = Q.peek();
// Check right adjacent cell that if it can
// be rotten
if (isValid(temp.x + 1, temp.y)
&& arr[temp.x + 1][temp.y] == 1) {
if (!flag) {
// if this is the first orange to
// get rotten, increase count and
// set the flag.
b.add(new O(temp.x + 1,temp.y,ans));
ans++;
flag = true;
}
// Make the orange rotten
arr[temp.x + 1][temp.y] = 2;
// push the adjacent orange to Queue
temp.x++;
Q.add(new Ele(temp.x, temp.y));
// Move back to current cell
temp.x--;
}
// Check left adjacent cell that if it can
// be rotten
if (isValid(temp.x - 1, temp.y)
&& arr[temp.x - 1][temp.y] == 1) {
if (!flag) {
ans++;
flag = true;
}
arr[temp.x - 1][temp.y] = 2;
temp.x--;
Q.add(new Ele(
temp.x,
temp.y)); //
temp.x++;
}
// Check top adjacent cell that if it can be
// rotten
if (isValid(temp.x, temp.y + 1)
&& arr[temp.x][temp.y + 1] == 1) {
if (!flag) {
ans++;
flag = true;
}
arr[temp.x][temp.y + 1] = 2;
temp.y++;
Q.add(new Ele(
temp.x,
temp.y)); // Push this cell to Queue
temp.y--;
}
if (isValid(temp.x, temp.y - 1)
&& arr[temp.x][temp.y - 1] == 1) {
if (!flag) {
ans++;
flag = true;
}
arr[temp.x][temp.y - 1] = 2;
temp.y--;
Q.add(new Ele(
temp.x,
temp.y)); // push this to Queue
}
Q.remove();
}
Q.remove();
if (!Q.isEmpty()) {
Q.add(new Ele(-1, -1));
}
// If Queue was empty than no rotten oranges
// left to process so exit
}
// Return -1 if all arranges could not rot,
// otherwise ans
return (checkAll(arr)) ? -1 : ans;//ternary operator
}
}
void rules() {
System.out.println("\nLET'S PLAY ROTTEN ORANGES GAME ! ! ! \n");
System.out.println("ABOUT THE GAME --\n");
System.out.println(" Given a matrix of dimension M * N, where each cell in the matrix can have values 0, 1 or 2 which has the following meaning: \r\n"
+ "\n"
+ "0: Empty cell\r\n"
+ "1: Cells have fresh oranges\r\n"
+ "2: Cells have rotten oranges.\n");
System.out.println(" RULES AND INSTRUCTIONS :");
System.out.println(" -------------------------------------------------------------------------------------------------------------------------------");
System.out.println(" 1. The task is to find the minimum time required so that all the oranges become rotten (time in minute).");
System.out.println(" 2. A rotten orange at index (i,j ) can rot other fresh oranges which are its neighbors (up, down, left, and right)[in one minute].");
System.out.println(" 3. If it is impossible to rot every orange then simply write -1 ");
System.out.println(" -------------------------------------------------------------------------------------------------------------------------------\n");
}
}
class Nqueens{
int n;
Scanner sc=new Scanner(System.in);
char[][] q;
Nqueens(){
rules();
}
Nqueens(int n){
this.n=n;
q=new char[n][n];
}
void g() {
for(int i=0;i<n;i++ ) {
for(int j=0;j<n;j++){
q[i][j]='X';
}
}
}
void h(int row,char a[][]) {
if(row==n) {
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
System.out.print(" "+a[i][j]);;