Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. public class n1 {
  2.  
  3. public static void main(String[] args) {
  4. // 0 1 2 3 4 5
  5. int[][] arr = new int[20][20];
  6. for (int i = 0; i < arr.length; i++) {
  7. for (int j = 0; j < arr[i].length; j++) {
  8. arr[i][j] = i-j;
  9. }
  10. }
  11. toStringArr(arr);
  12.  
  13. for (int i = 0; i < arr.length; i++) {
  14. int temp = arr[0][i];
  15. arr[0][i] = arr[1][i];
  16. arr[1][i] = temp;
  17. }
  18. toStringArr(arr);
  19. }
  20. public static void toStringArr(int[][] arr) {
  21. String str = "";
  22. for (int i = 0; i < arr.length; i++) {
  23. for (int j = 0; j < arr[i].length; j++) {
  24. str += arr[i][j];
  25. str += " ";
  26. }
  27. str += "\n";
  28. }
  29. System.out.println(str);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement